Customer Credit Hold - CMOrderHed Dataset Update hit BPM Nullreferrence Error

Hi any expert may advice me on following error I hit, I has try many round on others method but still unable to find the solution.

My Error hit:
Exception > System.NullReferenceException: Object reference not set to an instance of an object. at Epicor.Customization.Bpm.DB44440CA484E04B41A66DAB920CA95B98.InTranDirective_Test_Credit_Limit_88D286313FE7442FBC6D3E75F01A31D4.A001_CustomCodeAction() in InTran.Test_Credit_Limi.cs:line 286

My BPM code as following:

The error hit after the line if (CMHed != null) I just not understand what error means Object reference not set to an instance of an object, which part i didn’t declare?

Now I figure out my error was come out from this line:

CMDataSet = hCM.GetOrders(CustID);

but i need to fill the tablesets of CMOrderHed and the statement is not correct. is there anyone able to assist?

I don’t see in your code where you set CustNum or CustID. How are those defined, and where do you initialize them?

Hi Doug, Thanks for your reply and sorry for my miss out which i has try many way whole day still not able to figure out, and following is my code.

I has check the tracing options that actually I have to call the GetByCustID first, but when i execute the code it return error which is Records Not Found! but my Cust ID really exist in db.
secondly the GetOrders should be return me a tablesets of CMOrderHed if I successfully call the GetByCustID.

for the CMDataset = hCM.GetOrders(“H0012”); I have no idea might be is not working at all or I miss out something to inject the data to my tablesets.

kindly please advice.

Try using:

hCM = Ice.Assemblies.ServiceRenderer.GetService<CreditManagerSvcContract>(Db);

EDIT: I followed your logic using BL Tester and I got the expected dataset on GetOrders.

I would put a check on the CMDataSet after the GetOrders to make sure it’s not null.

After modifying the bpm restart the app pool, I seem to recall this was needed on my last test although I could be wrong, worth a try.

Your last code example looks good.

thanks Jonathan and will try on this, and will try this on my test env.

Thanks Doug.C, will try on this on my code, I did the same try on BL tester on the GetOrders, its returns a blank row with all null value fields, may I know how you test and mind to share with me?

It very funny for just a simple declare the datasets and it return me an error:
System.NullReferenceException: Object reference not set to an instance of an object

means system unable to understand what is CMDataSet about even been declare and try to fill it with result.

I entered the customer id in the field:

I then clicked “Invoke” and got the following:

I clicked on the CMOrderHed and got the following:

If you got a blank row, then it’s not getting any orders for that customer. I’m guessing there are some orders for them in your system? I tried it on a customer with no orders and got a null dataset back.

Thanks and appreciate for the tips, will do this check from my end and guess really might be not from my code.

But my last test still no luck and I did check the BL tester the row was there in list, and when come to the line:
CMDataSet = hCM.GetOrders(22123);

Its not able to store or pull the row into CMDataSet as following error:
System.NullReferenceException: Object reference not set to an instance of an object

Doesn’t GetOrders require a string as a parameter?

Yup, GetOrders BO require string as CustID, i try to insert ref CMDataSet is not working due to the definition format not allow.

The method only needs the Customer ID as string, are you sure the object reference error happens when calling GetOrders?

Can you show the setup used for the bpm? I’m not familiar with bpms so I would like to see the setup to try and replicate from my side if I get the error.

Are you doing this as a data directive? Or as a method directive? If so which table/process? I’ll model it in my sandbox to see if I can figure out what’s going on.

Hi Doug thanks,
I model this in data directive, the purpose of this for un-hold the order credit been hold which can be view at Customer Credit Manager.
I’m actually fire this data directive at task schedule db, and the bpm will open mailbox to read the mail responded from HOD who send the signal to un-hold the order credit.

hm… sorry and sound complicated ya… but anyway the main issue cause at the section code which trying to un-hold the credit order only, the rest function are working fine.

I did try to code it at screen customization which can be work perfectly, but I always hit the issue in BPM custom code on using BO to update the order status.

Just one more question … do you have multiple companies in your database? Or just one?

Yes Doug, I have here multiple company with multiple plant too. thanks

Could it be the BPM is firing in a company that doesn’t have the data you’re looking for?

hmm nop, i did query result test before fire the bpm, of-cause have to ensure the data is there before fire the bpm.
I have the similar code in screen customization which is working, and my problem is I’m not that skillful on BPM object custom coding, so would like to seek for your expert advice.