Epicor Functions ... Error

Trying to create a function that should eventually create the Req Head, however getting the following Error:
System.ArgumentException: The argument ‘connectionString’ cannot be null, empty or contain only white space.

My Code is below:

/-------START----------/
int ReqNumber = 0;

Ice.IceDataContext Db = new Ice.IceDataContext() ;
Erp.Contracts.ReqSvcContract objReq = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ReqSvcContract>(Db, true);
Erp.Tablesets.ReqTableset Reqds = new Erp.Tablesets.ReqTableset();
objReq.GetNewReqHead(ref Reqds);
Reqds.ReqHead[0][“Company”] = “ABC”;
Reqds.ReqHead[0][“OpenReq”] = true;

                      Reqds.ReqHead[0]["RowMod"] = 'A';
                      
                      objReq.Update(ref Reqds);  
                      
                       ReqNumber = Convert.ToInt32(Reqds.ReqHead[0].ReqNum);

/-------END----------/

Epicor: 2021.1.9
Please suggest !

try

Epicor.Functions.IFunctionHost host = (Epicor.Functions.IFunctionHost)this.GetType().BaseType.BaseType.GetField(“host”, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
var Dbl = (Erp.ErpContext)host.GetIceContext();

Functions can call BOs natively now and also write to Db natively you should not be making your own context

2 Likes

Any documentation ?

Sure thing the help has a ton of it built right into epicor. You can also use the widgets to do almost anything.

Through Widgets only, it has started working, but this is bit longer to add widgets for each n every field set/get, condition checks, calling BOs etc.
The Custom Code way is the flexible and faster way to write complex in nature codes.

Thanks jose

Faster to write sure, but way easier to make a mistake and the code doesn’t upgrade cleanly.

1 Like