Custom Code Printing AR Invoice Form -> "Invalid AgentID"

Have a function to submit an AR Invoice form to System agent.

I am getting an exception “Invalid AgentID”

I looked in System Agent Maintenance and the ID is set to “SystemAgentID”
I’ve tried that, also setting it to WorkstationID, also leaving it blank

The trace in Kinetic developer tools has it as blank

This is my code: (function)

 this.CallService<Erp.Contracts.ARInvFormSvcContract>(arInvFrm => 
    {
        var arInvFrmTs = arInvFrm.GetNewParameters();
        
        arInvFrmTs.ARInvFormParam[0].InvoiceNum = iInvoiceNum;

        // arInvFrmTs.ARInvFormParam[0].AgentID = "SystemTaskAgent";
        arInvFrmTs.ARInvFormParam[0].AgentID = this.Session.WorkstationID;
        arInvFrmTs.ARInvFormParam[0].AutoAction = "SSRSPreview";
        arInvFrmTs.ARInvFormParam[0].CalledFrom = "Erp.UI.ARInvoiceEntry";
        arInvFrmTs.ARInvFormParam[0].ReportStyleNum = iReportStyleNum;
        arInvFrmTs.ARInvFormParam[0].SSRSRenderFormat = "PDF";
        arInvFrmTs.ARInvFormParam[0].SSRSEnableRouting = ! iPreviewOnly;
        // arInvFrmTs.ARInvFormParam[0].TaskNote = taskNote;
        
        arInvFrmTs.ARInvFormParam[0].WorkstationID = this.Session.WorkstationID;

        // arInvFrm.RunDirect(arInvFrmTs);
        arInvFrm.SubmitToAgent(arInvFrmTs, "SystemAgent", 0, 0, "Erp.UIRpt.ARInvForm");
    });

1 Like

This BO? Erp.Contracts.ARInvFormSvcContract

yep, sorry, just noticed 1st line was not displayed

My code from function that does the same:

      string uniqueStringToIdentifyReport = Guid.NewGuid().ToString();
    
      CallService<Erp.Contracts.ARInvFormSvcContract>(ari =>
      {
          var ariTS = ari.GetNewParameters();
          
          var ariParams = ariTS.ARInvFormParam.FirstOrDefault();
          
          ariParams.InvoiceNum = InvoiceNum;
      
          ariParams.AutoAction = SSRSAction.ToUpper();
          ariParams.WorkstationID = "web_" + Session.UserID;
          ariParams.ReportStyleNum = ReportStyle;
          ariParams.TaskNote = uniqueStringToIdentifyReport;
          
          ari.RunDirect(ariTS);
      });
      
      
      var reportDataBytes = (from sysReport in Db.SysRptLst
                    join sysTask in Db.SysTask on
                    sysReport.SysTaskNum equals sysTask.SysTaskNum
                    where sysTask.TaskNote == uniqueStringToIdentifyReport
                    select sysReport.RptData).FirstOrDefault();
    
    
      if(reportDataBytes != null)
      {
          ReportB64 = System.Convert.ToBase64String(reportDataBytes);
      }

Let me try the submittoagent real quick.

Looks like I have that precoded, un momento.

1 Like

oh ffs, report not in pilot lol, one more sec

It did work for me with the RunDirect which kind of makes sense because it doesn’t need an agent

but I don’t really want to read the data back, I just wanna pop open the preview or in another case send an email (we are using APR break/routing rules)

My ssrs is acting funny, here test this code for submittoagent


      string uniqueStringToIdentifyReport = Guid.NewGuid().ToString();

      CallService<Erp.Contracts.ARInvFormSvcContract>(ari =>
      {
          var ariTS = ari.GetNewParameters();
          
          var ariParams = ariTS.ARInvFormParam.FirstOrDefault();
          
          ariParams.InvoiceNum = InvoiceNum;
      
          ariParams.AutoAction = SSRSAction.ToUpper();
          ariParams.WorkstationID = "web_" + Session.UserID;
          ariParams.ReportStyleNum = ReportStyle;
          ariParams.TaskNote = uniqueStringToIdentifyReport;
          
          ari.SubmitToAgent(ariTS, "SystemTaskAgent", 0, 0, "Erp.UIRpt.ARInvForm");

Hmmm, you’re not even setting AgentID, which I’ve tried but still errors.

Maybe it’s how you have WorkStationID wired up, mine is different, I’ll give that a try

Is NOT a workstation id.

You used to be able to use
$"{Session.ClientComputerName} {Session.ClientTerminalID}"
but that broke and I’m not sure it has been fixed.

$"{Session.ClientComputerName} {Session.ClientTerminalID}"

and $"web_{Session.UserID}" both seems to work now

I’d use the latter.

That works for you ? (not for me)
I printed my AgentID and it looks legit “web_ScottJ”

wanna send me your last code set ?
I’ll try it verbatim

thanks

What I posted last is what I use. What did the system agent say?

and you successfully set AgentID using $“web_{Session.UserID}” ?

I switched my code to be setup same as yours and set the AgentID to above, still get the error

It never gets to the system agent, the SubmitToAgent call throws an exception in the function and it dies there.

The odd thing is if I look at the trace (network/payload) from using the standard print screen that field is empty in the json for the dataset.

If I use that same payload in a REST testing tool it works,

Yet, if I set ALL the parameters in the ARInvFormParam’s row to the same values of the payload in the function I get the error - makes no sense.

I opened a ticket with Epicare but I’m sure the response will be, “we don’t help with customizations”

thanks for your efforts tho

I don’t set the AgentID at all. That is already set from GetNewParameters();

The WorkstationID is what I set to $"web_{Session.UserID}".

Yeah, that was one of the first things I tried (not setting AgentID), still got the error…this is what I currently have just to be clear

    this.CallService<Erp.Contracts.ARInvFormSvcContract>(arInvFrm => 
    {
        var arInvFrmTs = arInvFrm.GetNewParameters();
        var ariParams = arInvFrmTs.ARInvFormParam.FirstOrDefault();
        
        ariParams.InvoiceNum = iInvoiceNum;

        ariParams.AutoAction = "SSRSPreview";
        ariParams.CalledFrom = "Erp.UI.ARInvoiceEntry";
        ariParams.ReportStyleNum = iReportStyleNum;
        ariParams.SSRSRenderFormat = "PDF";
        ariParams.SSRSEnableRouting = ! iPreviewOnly;
        ariParams.TaskNote = Guid.NewGuid().ToString();
        
        ariParams.WorkstationID = "web_" + Session.UserID;
        
        // arInvFrm.RunDirect(arInvFrmTs);
        arInvFrm.SubmitToAgent(arInvFrmTs, "SystemAgent", 0, 0, "Erp.UIRpt.ARInvForm");
    });

uhmmmm lol

try this

this.CallService<Erp.Contracts.ARInvFormSvcContract>(arInvFrm => 
{
    var arInvFrmTs = arInvFrm.GetNewParameters();
    var ariParams  = arInvFrmTs.ARInvFormParam.FirstOrDefault();
        
    ariParams.InvoiceNum = iInvoiceNum;

    ariParams.AutoAction = "SSRSPREVIEW";
    ariParams.ReportStyleNum = iReportStyleNum;
        
    ariParams.WorkstationID = "web_" + Session.UserID;
        
    arInvFrm.SubmitToAgent(arInvFrmTs, "SystemTaskAgent", 0, 0, "Erp.UIRpt.ARInvForm");
});
1 Like

well, that gave me a different result at least…now a got a correlation Id error with no info on the detail screen except “Business Layer Exception”, but maybe it’s a step forward.

I’ll have to turn on server trace and see if I can find the error

Add a string output to your function

wrap it in this

try
{
    //code here
}
catch (Exception ex)
{
   yourNewOutput = ex.Message;
}

Then you can see what happened in the response from wherever you’re testing.