jkane
(John Kane)
September 7, 2023, 3:04pm
1
I am doing an efx and want to return a single row from a tableset. I believe I need to create the object as JobProdRow instead of var, but I am blanking on how to do it. Any help is appreciated.
var so = jeTableset.JobProd.Where(je=>je.Company == "X" && je.JobNum == jobNum)
.Select(je=>je).SingleOrDefault();
1 Like
What is going to consume this row? Do you want it to stay as a JobProdRow or will you need it as JSON?
jkane
(John Kane)
September 7, 2023, 3:13pm
3
Staying within the efx, so need it to be JobProdRow. I believe that would allow a single row to return? I believe the var is keeping it as a table?
klincecum
(Kevin Lincecum)
September 7, 2023, 3:16pm
4
That’s fine then. You can also leave out the .Select
and just go:
var so = jeTableset.JobProd.Where(je=>je.Company == "X" && je.JobNum == jobNum).SingleOrDefault();
1 Like
klincecum
(Kevin Lincecum)
September 7, 2023, 3:17pm
5
No, it will be a row.
If you want, make it:
JobProdRow so = jeTableset.JobProd.Where(je=>je.Company == "X" && je.JobNum == jobNum).SingleOrDefault();
and see for yourself.
jkane
(John Kane)
September 7, 2023, 3:19pm
6
I keep getting this error.
The table jeTableset.JobProd has more than one record
klincecum
(Kevin Lincecum)
September 7, 2023, 3:19pm
7
Without the rest of the code I’m lost.
jkane
(John Kane)
September 7, 2023, 3:20pm
8
var so = jeTableset.JobProd.Where(je=>je.Company == "GTRM" && je.JobNum == jobNum).SingleOrDefault();
var rec = soTableset.OrderDtl.Where(s=>s.Company == so.Company &&
s.OrderNum == so.OrderNum &&
s.OrderLine == so.OrderLine)
.Select(s=>s).SingleOrDefault();
List<string> label = new List<string>();
string location = XX;
string partNum = rec.PartNum.Replace(",","");
string partDesc = rec.LineDesc.Replace(",","");
string poNum = soTableset.OrderHed.Where(s=>s.Company == so.Company && s.OrderNum == so.OrderNum)
.Select(s=>s.PONum).FirstOrDefault();
string poLine = rec.POLine;
label.Add("Axcelis," + lblQty.ToString() + "," + partNum.ToString() + "," + partDesc.ToString() + "," + poNum.ToString() + "," + poLine.ToString());
string fileName = CompanyID.ToString() + "AxLabel" + DateTime.Now.Millisecond.ToString() + ".txt";
string pathString = location.ToString() + fileName.ToString();
System.IO.File.WriteAllLines(pathString, label);
klincecum
(Kevin Lincecum)
September 7, 2023, 3:22pm
9
One sec, had a contractor show up.
klincecum
(Kevin Lincecum)
September 7, 2023, 3:32pm
12
You change it in both places?
jkane
(John Kane)
September 7, 2023, 3:41pm
14
Full efx. First widget is Erp.JobEntry.GetByID. Second widget is Erp.SalesOrder.GetByID. Condition checks the Customer ID. Then my Custom Code from above. The last two are success and failure for REST call.
klincecum
(Kevin Lincecum)
September 7, 2023, 3:42pm
15
Disconnect the custom code block and see if it still errors out.
jkane
(John Kane)
September 7, 2023, 3:51pm
16
Shoot, it is the widget causing the error. Here I thought it was my code. Is there a way to return a single in an expression?
klincecum
(Kevin Lincecum)
September 7, 2023, 3:53pm
17
I honestly don’t know.
Since you got code already you could just do it all there ?
I cleaned your original a bit if you don’t mind.
var so = jeTableset.JobProd.Where(je =>
je.Company == "GTRM" &&
je.JobNum == jobNum).FirstOrDefault();
var rec = soTableset.OrderDtl.Where(s =>
s.Company == so.Company &&
s.OrderNum == so.OrderNum &&
s.OrderLine == so.OrderLine).FirstOrDefault();
List<string> label = new List<string>();
string location = XX;
string partNum = rec.PartNum.Replace(",","");
string partDesc = rec.LineDesc.Replace(",","");
string poNum = soTableset.OrderHed.Where(s=>s.Company == so.Company && s.OrderNum == so.OrderNum).FirstOrDefault().PONum;
string poLine = rec.POLine;
label.Add("Axcelis," + lblQty.ToString() + "," + partNum + "," + partDesc + "," + poNum + "," + poLine);
string fileName = CompanyID + "AxLabel" + DateTime.Now.Millisecond.ToString() + ".txt";
string pathString = location + fileName;
System.IO.File.WriteAllLines(pathString, label);
jkane
(John Kane)
September 7, 2023, 3:56pm
18
I try to avoid coding if I have to, but looks like I should use a code block to select a single OrderNum.
I never mind when someone who knows what they are doing fixes my stuff.
1 Like
gpayne
(Greg Payne)
September 7, 2023, 4:07pm
19
The expression only has to be valid C#. You can do a linq with FirstOrDefault from Db or your tableset
1 Like
Can you avoid the linq and just use a BAQ and the DynamicQuery business object?