Update field in another company using BPM

,

We are working on a Data Directive BPM on the OrderHed Table using (In Transaction)

What we want to do is when the orderHed.Checkbox02 is checked or unchecked in Company TGU it will update the OrderHed.Checkbox01 field in the GNC company.

The criteria for linking is stripping some characters off the end of the PO in TGU company and then linking that value to the OrderNum in the GNC company.

We have worked out code to strip the characters off the PO but too poor in the C# world to put it together. Here is the code Convert.ToInt32(ttOrderHedRow.PONum.Remove (ttOrderHedRow.PONum .Length -4,4))

We have also attached the starting BPM located in the TGU company.export.bpm (27.0 KB)

Here’s a post showing how to directly update a UD field in a DB. You’d want to tweak it so that the Company being referenced is the target company, and not the ClientContext.CurrentCompany

Yours would be something like:

Int32 oNum = Convert.ToInt32(ttOrderHedRow.PONum.Remove (ttOrderHedRow.PONum .Length -4,4));
// probably want to check that oNum has a non-zero value before doing the following

Db.OrderHed.Where( r =>r.Company == 'GNC' && r.OrderNum==oNum).FirstOrDefault().Checkbox01=1; // maybe "= true;"
Db.Validate();
1 Like

Thanks will give it a try. In a test environment of course.

image001.png

I am getting an error of “Too many characters in Character Literal”. The MyOrder and MyPrepared are variables I have set in the BPM prior to the custom code.

Below is the code I have

Db.OrderHed.Where( r =>r.Company == ‘GNC’ && r.OrderNum == MyOrder).FirstOrDefault().CheckBox02 = MyPrepared;
Db.Validate();

image001.png

Whoops … 'GNC' should be "GNC"

I figured out the single quotes need to be double quotes but when running the BPM the record is not updating. Any suggestions.

Attached is the updated BPM

image001.png

export2.bpm (27.1 KB)

I’m on 10.2.300, so I wouldn’t be able to load that BPM.

Also … Trying to update Checkbox01 or 02 in the GNC company’s OrderHed?

While your code is:

image

Thanks got it then tested but did not see the associated order updated. Any other suggestions?

image001.png

export2.bpm (27.1 KB)

Try that code but with fixed values for MyOrder and MyPrepared, to see if maybe they’re not exactly right. Like:

Db.OrderHed.Where( r =>r.Company == "GNC" && r.OrderNum == 12345).FirstOrDefault().CheckBox02 = 1;
Db.Validate();

(use a known ordernum in GNC for 12345)

Then try to set an OrderHed record in the TGU company. Just a check to see if being cross company is an issue

Db.OrderHed.Where( r =>r.Company == "TGU" && r.OrderNum == 12345).FirstOrDefault().CheckBox02 = 1;
Db.Validate();

Great eyes !!! That would make a difference. LOL

Got it working.

image001.png

1 Like