Bpm Custom Code Error

I created a Custom Code in BPM to look and if all firm release checkboxes in every line are checked check a box that i created on the OrderHed called FirmReleaseAll_c

i run the code and I keep getting this error

Error CS0120: An object reference is required for the non-static field, method, or property ‘Erp.Tables.OrderHed.FirmReleaseAll_c.get’ [InTran.FirmReleaseAll.cs(180,9)]

What am I doing wrong in my code?

This is my code:

Erp.Tables.OrderRel OrderRel;
foreach (var ttOrderHedRow in ttOrderHed)
{
foreach (var OrderRel_iterator in (from OrderRel_Row in Db.OrderRel
where OrderRel_Row.Company == ttOrderHedRow.Company
&& OrderRel_Row.OrderNum == ttOrderHedRow.OrderNum
select OrderRel_Row))
{
OrderRel = OrderRel_iterator;

		if (OrderRel.FirmRelease = true)
{
    OrderHed.FirmReleaseAll_c = true;
}

}}

Add

Erp.Tables.OrderHed OrderHed;

above your code and see if that works.

Also, you’ll want to line up the OrderHed record with your ttOrderHed record…

I entered that on the top and now i get this Error

Error CS0165: Use of unassigned local variable ‘OrderHed’ [InTran.FirmReleaseAll.cs(181,7)]

What do you mean by line it up? Sorry I am a beginner when it comes to C# coding

You could do something like this. I did not check syntax and it could be simplified

Erp.Tables.OrderRel OrderRel;
bool AllLinesFirm = true;
foreach (var ttOrderHedRow in ttOrderHed)
{
	foreach (var OrderRel_iterator in (from OrderRel_Row in Db.OrderRel
		where OrderRel_Row.Company == ttOrderHedRow.Company
		&& OrderRel_Row.OrderNum == ttOrderHedRow.OrderNum 
		&& OrderRel_Row.FirmRelease == false
		select OrderRel_Row))
		{
			AllLinesFirm = false;
		}
		if (AllLinesFirm) {ttOrderHedRow["FirmReleaseAll_c"] = true;} else {ttOrderHedRow["FirmReleaseAll_c"] = false;}
}

Here is a template I use. It is pretty much plug and play. Check how you are referencing the variables. You will need the code inside the outer set of {} for every table you are using. So where as you are using both OrderHed and OrderRel, these both need to be declared. You need to add the OrderDtl in there as well, in the case of multiple detail lines. In which case you would simply use the template code inside the OrderDtl {} section. Just as a double check, be sure after you created your new field that you regenerate the data module.

Erp.Tables.XXX XXX;

foreach (var XXX_Recs in (from XXX_Row in Db.XXX
where XXX_Row. Company == Session.CompanyID
&& XXX_Row.YYY == ZZZ_Recs.YYY
select XXX_Row))
{
var XXXRow = XXX_Recs;
if (XXX_Recs != null)
{
callContextBpmData.CCC = XXX_Recs.YYY;
}
} /*** XXX ***/

Working Example:

Erp.Tables.OrderHed OrderHed;
Erp.Tables.OrderDtl OrderDtl;

var OrderHed_Recs = (from OrderHed_Row in Db.OrderHed
where OrderHed_Row.Company == Session.CompanyID
&& OrderHed_Row.OrderNum == CurOrderNum
select OrderHed_Row).FirstOrDefault();
{
var OrderHedRow = OrderHed_Recs;
if (OrderHed_Recs != null)
{
foreach (var OrderDtl_Recs in (from OrderDtl_Row in Db.OrderDtl
where OrderDtl_Row. Company == Session.CompanyID
&& OrderDtl_Row.OrderNum == OrderHed_Recs.OrderNum
select OrderDtl_Row))
{
var OrderDtlRow = OrderDtl_Recs;
if (OrderDtl_Recs != null)
{
}
} /*** OrderDtl /
}
} /
OrderHed ****/

Brenda J. Mohr
Humtown Products
Phone: 330-482-5555

1 Like

This can be done without special code through the BPM Workflow Designer.

Post-Processing Method Directive on SalesOrder.Update Method.

1 Like

Thanks for the outline, I’m new to code in BPMs so the template will help. Question, is “CurOrderNum” a built in variable for method BPMs I assume if true.

@bmgarver What did you use in the Set Field of a Post-Processing to actually change the OrderHed table. I don’t believe setting ttOrderHed.FieldName would do anything on a post.

i tried this and it force checks the firmrelease and firmreleaseall_c after being saved

Because “FirmReleaseAll_c” is a custom filed so you need used as ttOrderHedRow[“FirmReleaseAll_c”] = true; (or false)

2 Likes

Been awhile since I wrote this, but, yes I believe that is true.

Brenda J. Mohr
Humtown Products