mbilodeau
(Mathieu Bilodeau)
February 24, 2023, 2:18pm
1
Hey guys,
I’ve got a dashboard with a button that calls an Epicor Function via Rest. The function takes a long time to process and I don’t want the UI to be frozen while waiting for the execution. What I would like is to send the function to the task agent, similar to the Schedule Epicor Function screen.
My problem is that I want to launch the execution of the function on demand with a button, obviously I don’t want to open the Schedule Epicor Function each time to “schedule” the function to run “now”.
Is there a way to achieve this ?
Thanks a lot
klincecum
(Kevin Lincecum)
February 24, 2023, 2:19pm
2
Ok, question 1.
Is this button on your dashboard just supposed to launch the function to run?
Or do you want it to return data?
mbilodeau
(Mathieu Bilodeau)
February 24, 2023, 2:20pm
3
Yes, exactly. The function does not need any parameter and does not return any value
klincecum
(Kevin Lincecum)
February 24, 2023, 2:22pm
4
Then you can schedule the function the same way epicor does.
3 Likes
klincecum
(Kevin Lincecum)
February 24, 2023, 2:26pm
5
<tracePacket>
<businessObject>Ice.Proxy.Proc.ScheduledFunctionImpl</businessObject>
<methodName>SubmitToAgent</methodName>
<appServerUri>https://centralusdtpilot08.epicorsaas.com/SaaS583Pilot/</appServerUri>
<returnType>System.Void</returnType>
<localTime>2/24/2023 08:25:01:6648486 AM</localTime>
<threadID>1</threadID>
<correlationId>94a74ff0-8156-4601-95b4-8fc136e391d5</correlationId>
<executionTime total="129" roundTrip="129" channel="0" bpm="0" bpmDataForm="0" other="0" />
<retries>0</retries>
<parameters>
<parameter name="ds" type="Ice.Proc.ScheduledFunctionsDataSet">
<ScheduledFunctionsDataSet xmlns="http://www.epicor.com/Ice/300/Proc/ScheduledFunction/ScheduledFunctions">
<ScheduledFunctionParam>
<FunctionDescription>Checks if services are reachable.</FunctionDescription>
<FunctionId>Pinger</FunctionId>
<LibraryDescription>Utility Functions</LibraryDescription>
<LibraryId>KEVUTILITY</LibraryId>
<ParameterValues>{"SysRowID":null}</ParameterValues>
<SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
<AutoAction></AutoAction>
<PrinterName></PrinterName>
<AgentSchedNum>0</AgentSchedNum>
<AgentID>SystemTaskAgent</AgentID>
<AgentTaskNum>0</AgentTaskNum>
<RecurringTask>false</RecurringTask>
<RptPageSettings></RptPageSettings>
<RptPrinterSettings></RptPrinterSettings>
<RptVersion></RptVersion>
<ReportStyleNum>0</ReportStyleNum>
<WorkstationID>KLWORKSTA124 1</WorkstationID>
<TaskNote></TaskNote>
<ArchiveCode>0</ArchiveCode>
<DateFormat>m/d/yyyy</DateFormat>
<NumericFormat>,.</NumericFormat>
<AgentCompareString></AgentCompareString>
<ProcessID></ProcessID>
<ProcessCompany></ProcessCompany>
<ProcessSystemCode></ProcessSystemCode>
<ProcessTaskNum>0</ProcessTaskNum>
<DecimalsGeneral>0</DecimalsGeneral>
<DecimalsCost>0</DecimalsCost>
<DecimalsPrice>0</DecimalsPrice>
<GlbDecimalsGeneral>0</GlbDecimalsGeneral>
<GlbDecimalsCost>0</GlbDecimalsCost>
<GlbDecimalsPrice>0</GlbDecimalsPrice>
<FaxSubject></FaxSubject>
<FaxTo></FaxTo>
<FaxNumber></FaxNumber>
<EMailTo></EMailTo>
<EMailCC></EMailCC>
<EMailBCC></EMailBCC>
<EMailBody></EMailBody>
<AttachmentType></AttachmentType>
<ReportCurrencyCode>USD</ReportCurrencyCode>
<ReportCultureCode>en-US</ReportCultureCode>
<SSRSRenderFormat></SSRSRenderFormat>
<UIXml></UIXml>
<PrintReportParameters>false</PrintReportParameters>
<SSRSEnableRouting>false</SSRSEnableRouting>
<DesignMode>false</DesignMode>
<RowMod>A</RowMod>
</ScheduledFunctionParam>
</ScheduledFunctionsDataSet>
</parameter>
<parameter name="agentID" type="System.String"><![CDATA[SystemTaskAgent]]></parameter>
<parameter name="agentSchedNum" type="System.Int64"><![CDATA[0]]></parameter>
<parameter name="agentTaskNum" type="System.Int32"><![CDATA[0]]></parameter>
<parameter name="maintProgram" type="System.String"><![CDATA[Ice.Services.Proc.ScheduledFunction]]></parameter>
</parameters>
<paramDataSetChanges>
<paramDataSet name="ds" useDataSetNbr="0">
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="FunctionDescription"><![CDATA[Checks if services are reachable.]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="FunctionId"><![CDATA[Pinger]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="LibraryDescription"><![CDATA[Utility Functions]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="LibraryId"><![CDATA[KEVUTILITY]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ParameterValues"><![CDATA[{"SysRowID":null}]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="SysRowID"><![CDATA[00000000-0000-0000-0000-000000000000]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="AutoAction"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="PrinterName"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="AgentSchedNum"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="AgentID"><![CDATA[SystemTaskAgent]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="AgentTaskNum"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="RecurringTask"><![CDATA[False]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="RptPageSettings"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="RptPrinterSettings"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="RptVersion"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ReportStyleNum"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="WorkstationID"><![CDATA[KLWORKSTA124 1]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="TaskNote"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ArchiveCode"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="DateFormat"><![CDATA[m/d/yyyy]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="NumericFormat"><![CDATA[,.]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="AgentCompareString"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ProcessID"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ProcessCompany"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ProcessSystemCode"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ProcessTaskNum"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="DecimalsGeneral"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="DecimalsCost"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="DecimalsPrice"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="GlbDecimalsGeneral"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="GlbDecimalsCost"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="GlbDecimalsPrice"><![CDATA[0]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="FaxSubject"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="FaxTo"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="FaxNumber"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="EMailTo"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="EMailCC"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="EMailBCC"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="EMailBody"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="AttachmentType"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ReportCurrencyCode"><![CDATA[USD]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="ReportCultureCode"><![CDATA[en-US]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="SSRSRenderFormat"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="UIXml"><![CDATA[]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="PrintReportParameters"><![CDATA[False]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="SSRSEnableRouting"><![CDATA[False]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="DesignMode"><![CDATA[False]]></changedValue>
<changedValue tableName="ScheduledFunctionParam" rowState="Added" rowNum="0" colName="RowMod"><![CDATA[A]]></changedValue>
</paramDataSet>
</paramDataSetChanges>
</tracePacket>
4 Likes
mbilodeau
(Mathieu Bilodeau)
February 24, 2023, 2:31pm
6
This looks like exactly what I need, I’ll make some tests.
Thanks
2 Likes
mbilodeau
(Mathieu Bilodeau)
February 24, 2023, 3:30pm
7
Yep, works perfectly.
I ended up creating an Epicor Function called “ScheduleFunction”, which receives the library and FunctionID of the function to execute:
Here’s the details:
Thanks @klincecum
4 Likes
utaylor
(Utah Taylor)
February 24, 2023, 3:33pm
8
What’s the business case behind this? What are you accomplishing with this code?
mbilodeau
(Mathieu Bilodeau)
February 24, 2023, 3:47pm
9
From the dashboard, the user can change resource group / resource on job operation, and change some dates. Then we want to run a “custom global scheduling” epicor function, which reschedule jobs that respect some criterias, like some JobHead.PersonID for example.
This “custom global scheduling” epicor function is the one that I want to send to the task agent
4 Likes
datadaddy
(Scott Janisch)
September 19, 2023, 2:03pm
11
Nice, thanks for the complete example, do you know if it’s possible to pass parameters to the function ?
@klincecum ?
thx
2 Likes
mbilodeau
(Mathieu Bilodeau)
September 19, 2023, 3:02pm
12
Never tried passing parameters, maybe via CallContextBpmData ?
klincecum
(Kevin Lincecum)
September 19, 2023, 4:49pm
13
Yes, I’ll get back with you in a bit.
1 Like
klincecum
(Kevin Lincecum)
September 19, 2023, 7:39pm
14
I made a function to make this easier. I am using this currently for an automated process I have running after packs are marked shipped.
(Note, this function schedules for immediate run, it needs to be modified to do at a real scheduled time.)
Function: ScheduleFunction
Signature: IN
libraryID → System.String
functionID → System.String
parametersJson → System.String
try
{
CallService<Ice.Contracts.ScheduledFunctionSvcContract>(sf=>
{
ScheduledFunctionsTableset sfTS = new ScheduledFunctionsTableset();
sf.GetDefaults(ref sfTS);
ScheduledFunctionParamRow paramRow = sfTS.ScheduledFunctionParam.FirstOrDefault();
paramRow.LibraryId = libraryID;
paramRow.FunctionId = functionID;
paramRow.ParameterValues = parametersJson;
paramRow.RowMod = "A";
sf.SubmitToAgent(sfTS, "SystemTaskAgent", 0, 0, "Ice.Services.Proc.ScheduledFunction");
});
}
catch (Exception ex)
{}
–
It can be called like:
Dictionary<string, object> scheduledFunctionParametersDictionary = new Dictionary<string, object>();
scheduledFunctionParametersDictionary.Add("inputParamYouNeed1", whatyouaresendingforthisinputparam);
InvokeFunction("LibYouPutThisIn", "ScheduleFunction", "FunctionLibraryToCall", "FunctionToCall", JsonConvert.SerializeObject(scheduledFunctionParametersDictionary));
Edit , I had in error in the usage code, corrected.
4 Likes
datadaddy
(Scott Janisch)
September 19, 2023, 7:50pm
15
That is awesome, thanks !
1 Like
klincecum
(Kevin Lincecum)
September 19, 2023, 7:55pm
16
The gist of it is,
create a dictionary<string, object>
and add your stuff to it.
the string is the parameter name, and the object is the parameter itself.
then you just json serialize the dictionary and put it in the paramRow.ParameterValues
and schedule.
Easy Peasy.
1 Like
datadaddy
(Scott Janisch)
September 19, 2023, 7:56pm
17
if I have multiple inputs I would call this multiple times, correct ?
scheduledFunctionParametersDictionary.Add("inputParamYouNeed1", JsonConvert.SerializeObject(whatyouaresendingforthisinputparam));
klincecum
(Kevin Lincecum)
September 19, 2023, 10:20pm
19
I had an error there, sorry.
scheduledFunctionParametersDictionary.Add("inputParamYouNeed1", whatyouaresendingforthisinputparam);
There was a JsonConvert.SerializeObject()
in there, which was necessary for the code I pulled it from, but not part of the way you call it normally. My method was expecting a dataset in json format, yada yada yada
I corrected the code above.
1 Like
datadaddy
(Scott Janisch)
September 20, 2023, 2:52pm
20
got it, that makes more sense to me now, it thru me off a bit, but as of yet I haven’t had a chance to try it out…thanks again