1
votes

I am using Java to get a Acumatica report using screen based SOUP Web Services (code generated using Apache CXF). The report I am interested in is Transactions for Periods in Finance. I know how to pass commands to the web service to specify returned results, but I don't know how to pass parameters.

The parameters I want to pass are fromPeriod, toPeriod, Ledger, fromAccount and toAccount. Do I pass the parameters as filters or some other way? If as filters, how do I create the filter objects?

I can not find any examples in Java for calling Acumatica SOAP Web Services, so any help is much appreciated.


screen = service.getScreenSoap();
LoginResult lres = screen.login(username, password);

Content content = screen.getSchema();  
ArrayOfFilter filters = new ArrayOfFilter();

ArrayOfCommand commands = new ArrayOfCommand();

commands.getCommand().add(content.getReportResults().getHtmlContent());
ArrayOfArrayOfString result = screen.export(commands, filters, 0, true, true);
List<ArrayOfString> lines = result.getArrayOfString();

If I call the report without parameters I get the following errors:

javax.xml.ws.soap.SOAPFaultException: 
System.Web.Services.Protocols.SoapException: 
Server was unable to process request. --> PX.Data.PXViewDoesNotExitException: 
Error: The view Parameters doesn't exist.

I changed my code to match C# code in the answer:

              Content content = screen.getSchema();  
              ArrayOfFilter filters = new ArrayOfFilter();

              Value fromPeriod = new Value();
              fromPeriod.setLinkedCommand(content.getParameters().getFromPeriod());
              fromPeriod.setValue("06-2018");

              Value toPeriod = new Value();
              toPeriod.setLinkedCommand(content.getParameters().getToPeriod());
              toPeriod.setValue("06-2018");

              Value ledger = new Value();
              ledger.setLinkedCommand(content.getParameters().getLedger());
              ledger.setValue("ACTUAL");

              Value company = new Value();
              company.setLinkedCommand(content.getParameters().getCompany());
              company.setValue("PRODUCTS");

              Value branch = new Value();
              branch.setLinkedCommand(content.getParameters().getBranch());
              branch.setValue("PRODWHOLE");

              ArrayOfCommand commands = new ArrayOfCommand();
              commands.getCommand().add(content.getReportResults().getHtmlContent());
              commands.getCommand().add(fromPeriod);
              commands.getCommand().add(toPeriod);
              commands.getCommand().add(ledger);
              commands.getCommand().add(company);
              commands.getCommand().add(branch);

              ArrayOfArrayOfString result = screen.export(commands, filters, 0, true, true);

I now get a new error:

javax.xml.ws.soap.SOAPFaultException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null. Parameter name: key at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at PX.Data.PXViewCollection.get_Item(String key) at PX.Api.SyImportProcessor.ExportTableHelper..ctor(SyExportContext context, Boolean submit) at PX.Api.ScreenUtils.a(String A_0, Command[] A_1, Int32 A_2, Int32 A_3, Boolean A_4, Boolean A_5, Dictionary2 A_6, OptimizedExportProviderBuilderForScreenBasedApi A_7, Boolean A_8, PXViewDescription[] A_9, ScreenInfo A_10, HashSet1 A_11, Dictionary2 A_12, SyExportContext A_13) at PX.Api.ScreenUtils.ExportInternal(String screenId, Command[] commands, Filter[] filters, Int32 startRow, Int32 topCount, Boolean includeHeaders, Boolean breakOnError, PXGraph graph, Boolean bindGuids, Boolean mobile, Boolean isSelector, String forcePrimaryView, String bindContainer, Dictionary2 sorts, String guidViewName, OptimizedExportProviderBuilderForScreenBasedApi buildOptimizedExportProviderDelegate, Func3 serializationDelegate) at PX.Api.Services.ScreenService.Export(String id, Command[] commands, Filter[] filters, Int32 startRow, Int32 topCount, Boolean includeHeaders, Boolean breakOnError, Boolean bindGuids, Boolean mobile, Boolean isSelector, String forcePrimaryView, PXGraph forceGraph, String bindContainer, Dictionary2 sorts, String guidViewName, Boolean disableOptimizedExport) at PX.Api.Soap.Screen.ScreenGate.Export(Command[] commands, Filter[] filters, Int32 topCount, Boolean includeHeaders, Boolean breakOnError) --- End of inner exception stack trace --- at org.apache.cxf.jaxws.JaxWsClientProxy.mapException(JaxWsClientProxy.java:195) ~[cxf-rt-frontend-jaxws-3.3.2.jar:3.3.2] at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145) ~[cxf-rt-frontend-jaxws-3.3.2.jar:3.3.2] at com.sun.proxy.$Proxy45.export(Unknown Source) ~[?:?] at com.appcomputing.be.acdata.acumatica.gl633000.GL633000.getReport(GL633000.java:89) [classes/:?] at com.appcomputing.be.acdata.acumatica.gl633000.GL633000.main(GL633000.java:115) [classes/:?] Caused by: org.apache.cxf.binding.soap.SoapFault: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null. Parameter name: key at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at PX.Data.PXViewCollection.get_Item(String key) at PX.Api.SyImportProcessor.ExportTableHelper..ctor(SyExportContext context, Boolean submit) at PX.Api.ScreenUtils.a(String A_0, Command[] A_1, Int32 A_2, Int32 A_3, Boolean A_4, Boolean A_5, Dictionary2 A_6, OptimizedExportProviderBuilderForScreenBasedApi A_7, Boolean A_8, PXViewDescription[] A_9, ScreenInfo A_10, HashSet1 A_11, Dictionary2 A_12, SyExportContext A_13) at PX.Api.ScreenUtils.ExportInternal(String screenId, Command[] commands, Filter[] filters, Int32 startRow, Int32 topCount, Boolean includeHeaders, Boolean breakOnError, PXGraph graph, Boolean bindGuids, Boolean mobile, Boolean isSelector, String forcePrimaryView, String bindContainer, Dictionary2 sorts, String guidViewName, OptimizedExportProviderBuilderForScreenBasedApi buildOptimizedExportProviderDelegate, Func3 serializationDelegate) at PX.Api.Services.ScreenService.Export(String id, Command[] commands, Filter[] filters, Int32 startRow, Int32 topCount, Boolean includeHeaders, Boolean breakOnError, Boolean bindGuids, Boolean mobile, Boolean isSelector, String forcePrimaryView, PXGraph forceGraph, String bindContainer, Dictionary2 sorts, String guidViewName, Boolean disableOptimizedExport) at PX.Api.Soap.Screen.ScreenGate.Export(Command[] commands, Filter[] filters, Int32 topCount, Boolean includeHeaders, Boolean breakOnError) --- End of inner exception stack trace ---

I finally got the webservice to work after replacing the screen.export(...) with screen.submit(commands). But the result just has a long binary (non-text) string.

If anyone can help interpret this string (we need the data values in the report) that would be very useful

1

1 Answers

0
votes

This code example is in C# and it is for pdf file, but I think it may be useful. It is pretty much self explanatory:

//Getting the printable version of an invoice
//on the Invoice & Memo form (S0643000)
public static void GetPrintableInvoice()
{
    //Invoice data
    string docType = "Invoice";
    string invoiceNbr = "INV000045";
    using
    (
    //Connect to the web services and log in to Acumatica ERP
    Screen context = WebServiceConnector.InitializeWebService())
    {
        try
        {
            //Get the schema of the Invoice & Memo form (S0643000)
            SO643000Content invoiceFormSchema = context.SO643000GetSchema();
            //Specify the needed invoice and get a PDF version of it
            var commands = new Command[]
            {
                new Value
                {
                    Value = docType,
                    LinkedCommand = invoiceFormSchema.Parameters.DocumentType
                },
                new Value
                {
                    Value = invoiceNbr,
                    LinkedCommand = invoiceFormSchema.Parameters.ReferenceNumber
                },
                invoiceFormSchema.ReportResults.PdfContent
            };
            //Submit the commands to the form
            SO643000Content[] pdfInvoice = context.SO643000Submit(commands);
            //Save the result in a PDF file
            if (pdfInvoice != null && pdfInvoice.Length > 0)
            {
                File.WriteAllBytes(string.Format(@"Invoice_{0}.pdf", invoiceNbr),
                Convert.FromBase64String(pdfInvoice[0].ReportResults.PdfContent.Value));
            }
        }
        finally
        {
            //Log out from Acumatica ERP
            context.Logout();
        }
    }
}

So, in your case it should be something like that:

screen = service.getScreenSoap();
LoginResult lres = screen.login(username, password);

Content content = screen.getSchema();  
ArrayOfFilter filters = new ArrayOfFilter();

ArrayOfCommand commands = new ArrayOfCommand();

commands.getCommand().add(content.getValue("ParamValue",content.Parameters.fromPeriod));
commands.getCommand().add(content.getReportResults().getHtmlContent());
ArrayOfArrayOfString result = screen.export(commands, filters, 0, true, true);
List<ArrayOfString> lines = result.getArrayOfString();

Basically, you set parameter values the same way you set values for fields when you update a record