BPM code Send to PO from Req

Hi Any Expert here to advise me is there something I did wrongly in my code for BPM custom code.
I would like to use BPM code to automatically dispatch my Requisition Send to PO stage but I hit an error as following, I had did many way to change the coding logic but still no luck.

                var ReqDataSet = new  Erp.Tablesets.ReqTableset(); 
                Erp.Contracts.ReqSvcContract hReq = null;                    
                hReq = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ReqSvcContract>(Db); 
                if (hReq != null)
                {
                  ReqDataSet = hReq.GetByID(1234);
                  hReq.BuildNextDispatcher("PO", out a, out b);
                  var RHed = (from RH in ReqDataSet.ReqHead where RH.ReqNum == 1234 select RH).SingleOrDefault();
                  if (RHed != null)
                  {
                    RHed.NextActionID = "PO";
                    RHed.NextActionDesc = "Create Purchase Order";
                    RHed.ReplyOption = "A";
                    RHed.ReqUserId = "PRUser";
                    RHed.RowMod = "U";
                    hReq.Update(ref ReqDataSet);
                    hReq.CheckToDo(auth.RequestorID);
                    hReq.RDMenuFlags(iPR,auth.RequestorID,out c, out d);
                    hReq.GetReqLogList("ReqNum = '" + sPR + "'", 100, 1, out c);
                  }
                }

as i hit the following error:
Program Ice.Services.Lib.RunTask raised an unexpected exception with the following message: RunTask: BPM runtime caught an unexpected exception of ‘ArgumentNullException’ type.
See more info in the Inner Exception section of Exception Details.
Stack Trace:
at Epicor.Customization.Bpm.DirectiveBase`3.Execute(TParam parameters) in C:_Releases\ICE\ICE3.2.400.0\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 162

and also I found this error line as follow:

Inner Exception:
Value cannot be null.
Parameter name: fromItem
Stack Trace:
at Epicor.Data.BufferCompare.Compare[TTypeFrom,TTypeTo](TTypeFrom fromItem, TTypeTo toItem, List1 usingList, List1 exceptForList, List`1 resultsList) in C:_Releases\ICE\ICE3.2.400.0\Source\Shared\Framework\Epicor.ServiceModel\Data\BufferCompare.cs:line 264
at Erp.Services.BO.ReqSvc.ReqHeadBeforeUpdate() in C:_Releases\ERP\UD10.2.400.18\Source\Server\Services\BO\Req\Req.cs:line 2255
at Erp.Services.BO.ReqSvc.OnRowEvent(DataTableEventType type, String tableName, IceRow row) in C:_Releases\ERP\UD10.2.400.18\Source\Server\Services\BO\Req\Req.Designer.cs:line 485

Appreciate if some one could advice.

1 Like

This dialect of the C# language seems to be unable to test a var for being null when it is, in fact, null.

Instead of if (RHed ! = null) try if(RHed.Any() )

and the same for your other if not null statements.

1 Like

Thanks Steve, i think BPM code does not recognize the code there

depending on where you are in your scope you might have to test the whole thing, like this:

if ((from d in Db.OrderDtl where d.OrderNum == oh.OrderNum select d).Any())

to use an example I just did a few days ago.

1 Like

I think just the term of .Any() is not found and need to search which reference should use, the definitely able to work in screen customization but i think is not working in BPM custom code.

I did test few way round by moving the line method up and down, but just does not have idea where the exception throw null value.

Thanks for your help Steve.

Sorry just to add on my error that i think my code does not have any syntax, the error which I attach from first was Run Time Error
I encounter the error come from the line when I try to update my dateset, something been null and unable to update to get through.

I would do it manually, tracing the Update dataset parameters. Then make sure when you do your code you have the same elements in your ReqDataSet set. My guess is one of the fields in your ReqDataSet is null and the BO is expecting a value.

Edit: On second thought, the error seems to stem from ReqHeadBeforeUpdate. So maybe there’s a field missing in a RHead element.

1 Like

Thanks Doug, and you are correct, is there any place to view the compulsory field or not null for the dataset, i did try on BL-Tester too but I’m still new to no idea how to check which field must not null.
This is my main issue which stuck me quite some time and not able to solve.

good point

there’s an object model reference kn epicweb you can download as a chm file

. Any() definitely works in my bpm code!

Maybe I has missing some reference for this to use the .Any()

image

I doubt it. The custom BPM code you enter gets automatically added to a source file with all the references.

You’ll have to debug, commenting out individual statements until you find the one causing the problem.

the .Any() is part of the C# System.Linq library. If you’re already using Linq then you should have it.

Hi Doug.C, my bad I didn’t call the Linq reference, i though it suppose BPM has automatically recognize it, by the way we use 10.2.400 only.

Sure and will do that and thanks for your advise.

What I was saying is .Any() will work as long as Linq is referenced, which based on your code it is.

Did you try replacing SingleOrDefault() with Any()?

Also, what BPM are you doing this with? Is it a Data Directive? Or is it a Method Directive? What point of the processing are you triggering your BPM?

First, more context will be needed, is this a method or data directive, what table\method, pre\post\intrans\standard

It looks to me the issue is happening in base code. Are you modifying a record before Epicor is trying to change it?

Regarding the Any(), it’s great. It’s a feature of Linq and Linq is configured by default in BPMs so you are good there. You could potentially start simplifying.

for example, do you still get the error if you comment our everything below RHed != null?

1 Like

Hi Doug,
I notice that the last line was updating UD_SysRevID but how would this define in code to update the system.byte[] ?
For the rest been filled except the UD_SysRevID.

 <changedValue tableName="ReqHead" rowState="Modified" rowNum="0" colName="NextActionDesc"><![CDATA[Create Purchase Order]]></changedValue>
  <changedValue tableName="ReqHead" rowState="Modified" rowNum="0" colName="NextActionID"><![CDATA[PO]]></changedValue>
  <changedValue tableName="ReqHead" rowState="Modified" rowNum="0" colName="ReplyOption"><![CDATA[A]]></changedValue>
  <changedValue tableName="ReqHead" rowState="Modified" rowNum="0" colName="UD_SysRevID"><![CDATA[System.Byte[]]]></changedValue>

The SysRevID is a timestamp (rowversion). You can leave that blank and it will auto fill in the database.