Auto-Approve PO using BPM

,

Same exact issue, null reference for setPORelShipToAddress

image

image

just to double check myself, I’m a complete noob with BPMs, could you tell me if this looks correct to you?

image

I’m not entirely sure what to enter as the viewName. In the trace it refrences POHeader, so that’s what I entered.

Why do you need the CheckBeforeUpdate and Update 1 after the ChangeAppSwitch?

I’m not saying that you definitely saying that you don’t need them. I’d have though that the ChangeAppSwitch would be the last thing to do on the PO.

I thought the same thing, as it seems to me the ChangeAppSwitch triggers the CheckBeforeUpdate and Update methods anyway.

So, I removed them and I’m back to square one. Null Reference Exception for setPORelShipToAddress

I think I may have stumbled on to it …

There’s a two distinct BO method’s (with very similar names) that are called when you approve a PO via the UI.

image

A trace of just clicking the Approved box, shows (in order):

  1. PO.ValidateAcctForGLControl
  2. PO.ChangeApproveSwitch
  3. PO.CheckBeforeUpdate
  4. PO.Update
  5. PO.ChangedApproveSwitch

Lines 2 and 5 are different methods!

I’ll give it a go

Same error… Maybe I’m doing something wrong with the way I’m passing the data between the widgets?

Look at this thread

1 Like

Well, that put me on the right track. The POs are now being approved correctly!

This was the code that did it for me:

var POApproveSwitchDataSet = new Erp.Tablesets.POTableset();
Erp.Contracts.POSvcContract hPOApproveHandle = null;
if (hPOApproveHandle == null) {
  hPOApproveHandle = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.POSvcContract>(Db);
} 

POApproveSwitchDataSet = hPOApproveHandle.GetByID(ttPOHeader.FirstOrDefault().PONum);
      
if (POApproveSwitchDataSet != null) {
  POApproveSwitchDataSet.POHeader[0].RowMod= "U";
  
  hPOApproveHandle.ChangeApproveSwitch(true,out ViolationMsg, ref POApproveSwitchDataSet);
      
  hPOApproveHandle.CheckBeforeUpdate(out str1, out str2, out str3, "", POApproveSwitchDataSet);
  hPOApproveHandle.Update(ref POApproveSwitchDataSet);
  
}

Had to create a couple variables (ViolationMsg, str1, str2, str3) and change the GetByID parameter to get it working but over all was pretty easy.

I’m sure I’ll have to adjust it a little to get it to work in the initial DD I was working on, turning it back into 1 BPM. Thanks Calvin!!

It’s a little disappointing that it couldn’t be done entirely in Widgets. One would think that calling the BO Method widgets in the right order -with an occasonal Set Field Widget - would be all that was needed. :frowning:

We both learned a lot on this. :slight_smile:

1 Like

Agreed, unfortunately there’s no set field widget in Standard DDs. Just Fill\Update by Query. I definitely learned a lot, was worth it, and I’m sure my employer will be most pleased haha. Thanks again!

I may have spoke too soon. It approves, but I’m missing some data and it’s acting strange.

First, it allows me to uncheck the Approve box… Normally I get a box stating “Record in process, unable to update” when trying to uncheck approve; pictured below.

image

Secondly, on the PO entry summary tab, the summary is not being updated, pictured below:

The line\release has the expected results though:

But if I try to delete the line, it does tell me the PO is approved and delete is not allowed:

image

Think I’m turning mole hills into mountains or should I not be concerned? Any ideas?

You don’t have that PO loaded in in PO entry when the DD runs, do you? If so, after the BPM runs, refresh the PO Entry form so that it has the latest data.

image

No sir, I’m opening the PO after the DD runs as the PO doesn’t exist until the DD runs.

Did you do all of the BO methods that happen when one clicks the Approved box in the UI?

A trace of just clicking the Approved box, shows (in order):

  1. PO.ValidateAcctForGLControl
  2. PO.ChangeApproveSwitch
  3. PO.CheckBeforeUpdate
  4. PO.Update
  5. PO.ChangedApproveSwitch

Lines 2 and 5 are different methods!

Pretty sure I am, this is what the code looks like now:

var POApproveSwitchDataSet = new Erp.Tablesets.POTableset();
Erp.Contracts.POSvcContract hPOApproveHandle = null;
if (hPOApproveHandle == null) {
  hPOApproveHandle = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.POSvcContract>(Db);
} 

POApproveSwitchDataSet = hPOApproveHandle.GetByID(POtable.POHeader.FirstOrDefault().PONum);
      
if (POApproveSwitchDataSet != null) {

  POApproveSwitchDataSet.POHeader[0].RowMod= "U";
  
  hPOApproveHandle.ValidateAcctForGLControl(POtable.POHeader.FirstOrDefault().PONum, out str1);

  hPOApproveHandle.ChangeApproveSwitch(true,out ViolationMsg, ref POApproveSwitchDataSet);
      
  hPOApproveHandle.CheckBeforeUpdate(out str2, out str3, out str4, "", POApproveSwitchDataSet);
  
  hPOApproveHandle.Update(ref POApproveSwitchDataSet);
  
  hPOApproveHandle.ChangedApproveSwitch(POtable.POHeader.FirstOrDefault().PONum, ref POApproveSwitchDataSet, out str5);
  
}

I’m still not sure about this line:

hPOApproveHandle.CheckBeforeUpdate(out str2, out str3, out str4, "", POApproveSwitchDataSet);

The fourth parameter, “”, is asking for the dataView. In the trace it references “POHeader” but tried that and receive an error.

I believe those parameters of type out (str1, str2, and str3) are to pass a string out of the function and into the variable specified. Do you declare str1 , str2, and str3 in your code?

For Shits-n-Giggles, I’d try the following:

string str1="";
string str2="";
string str3="";
hPOApproveHandle.CheckBeforeUpdate(out str1, out str2, out str3, "", POApproveSwitchDataSet);
MessageBox.Show("str1:" + str1 + "\nstr2: "+ str2 + "\nstr3: " + str3);

That would show if str1, str2 or str3 are being set to something.

I’m really just brainstorming here. Learning as we go …

No problem, I really appreciate the help, brainstorm away.

MessageBox wouldn’t work, had to use:

this.PublishInfoMessage("str2:" + str2 + "\nstr3: "+ str3 + "\nstr4: " + str4, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

But this was the results:

image

edit;

I really don’t think it’s the strings, I think it’s the dataView parameter that comes directly after str4. Also, I updated the code, I was missing ValidateAccForGLControl, but unforuntately that didn’t make a difference.

If you stop the BPM before it tries to do the approval part, and then look at it with PO Entry, does the summary page show the correct totals?

Sure doesn’t, great… I’ll have to nail this down before I worry about the approval process.

1 Like

I managed to get everything working correctly. I had to give up on the DD and move to a method directive. PO is created, everything looks correct and it’s being auto-approved.

Thanks again for the help @ckrusen!

1 Like