web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

to filter by query in sysoperation in x++

(1) ShareShare
ReportReport
Posted on by 1,836
hi ,
how can i filter by query in sysoperation i have added records to inculde in my contract class but its not working , here is my conract class code 
 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    [DataContractAttribute]
    final class DTPackingSlipNotInvoicedBatchContract
    {  
        smmBusRelMemo   subject,body;
        str             packedQuery;
        DTPackingSlipNotInvoiceType   type;
        Email            to;
        boolean          displayAmount;
    
    
        [
             DataMemberAttribute('Type'),
             SysOperationLabelAttribute(literalstr("Type")),
             SysOperationHelpTextAttribute(literalstr("Type")),
             SysOperationDisplayOrderAttribute('0')
        ]
        public DTPackingSlipNotInvoiceType   parmtype(DTPackingSlipNotInvoiceType   _type = type)
        {
            type = _type;
            return   type;
        }
    
        [
             DataMemberAttribute('Display Amount'),
             SysOperationLabelAttribute(literalstr("Display Amount")),
             SysOperationHelpTextAttribute(literalstr("Display Amount")),
             SysOperationDisplayOrderAttribute('1')
        ]
        public boolean   parmdisplayAmount(boolean  _displayAmount = displayAmount)
        {
            displayAmount = _displayAmount;
            return    displayAmount;
        }
    
        [
             DataMemberAttribute('To'),
             SysOperationLabelAttribute(literalstr("To")),
             SysOperationHelpTextAttribute(literalstr("To")),
             SysOperationDisplayOrderAttribute('2')
        ]
        public  Email parmTo(Email   _to = to)
        {
            to = _to;
            return    to;
        }
    
        [
             DataMemberAttribute('subject'),
             SysOperationLabelAttribute(literalstr("Subject")),
             SysOperationHelpTextAttribute(literalstr("Subject")),
             SysOperationDisplayOrderAttribute('3')
        ]
        public smmBusRelMemo  parmsubject(smmBusRelMemo  _subject = subject)
        {
            subject = _subject;
            return    subject;
        }
    
        [
            DataMemberAttribute('body'),
            SysOperationLabelAttribute(literalstr("Body")),
            SysOperationHelpTextAttribute(literalstr("Body")),
            SysOperationDisplayOrderAttribute('4')
        ]
        public smmBusRelMemo  parmbody(smmBusRelMemo  _body = body)
        {
            body = _body;
            return  body;
        }
    
        [ DataMemberAttribute,
           AifQueryTypeAttribute('_packedQuery', queryStr(DTHcmWorker))
        ]
    
          public str parmPackedQuery(str _packedQuery = packedQuery)
        {
            packedQuery = _packedQuery;
            return    packedQuery;
        }
    
        public Query getQuery()
        {
            Query q = new Query(SysOperationHelper::base64Decode(packedQuery));
            return q;
        }
    
        public void setQuery(Query _query)
        {
            packedQuery = SysOperationHelper::base64Encode(_query.pack());
        }
    
       
    
    }
    here is my code for conract , can any one suggest me what changes i have to make to apply filter ,
    thanks ,
    regards ,
    dinesh 
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dineshkarlekar,
     
    When you say it's not working what do you mean?

    Do you mean the dialog is not showing query filter? or when you run the code your filtration is not taken into account?

    Please share with us more details (you can include screenshots and more code)

    Thanks,
    Layan Jweihan
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi ,
     thanks for reply ,
    its showing the records to include and i am able to select records but , when i select the specific records and select ok then i have to generate result for specific records , can you help me on this , below is my code .
    final class DTPackingSlipNotInvoicedBatchController  extends SysOperationServiceController
    {
        protected void new()
        {
            super(classStr(DTPackingSlipNotInvoicedBatchService), methodStr(DTPackingSlipNotInvoicedBatchService,processoperation ), SysOperationExecutionMode::Synchronous);
        }
    
        public ClassDescription defaultCaption()
        {
            return "Process Job";
        }
    
        public static DTPackingSlipNotInvoicedBatchController construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)
        {
            DTPackingSlipNotInvoicedBatchController        controller;
            controller = new DTPackingSlipNotInvoicedBatchController();
            return controller;
        }
    
        public static void main(Args _args)
        {
            DTPackingSlipNotInvoicedBatchController       controller;
            controller = DTPackingSlipNotInvoicedBatchController::construct();
            controller.parmArgs(_args);
            controller.startOperation();
        }
    
    }
    final class DTPackingSlipNotInvoicedBatchService  extends SysOperationServiceBase
    {
        public void processoperation(DTPackingSlipNotInvoicedBatchContract  _contract)
        {
                    Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
                    Filename                                    fileName = "OpenTransaction_"+ "_contract.parmTo" + ".pdf";
                    SrsReportRunController                      controller = new SrsReportRunController();
                    SRSPrintDestinationSettings                 settings;
                    Array                                       arrayFiles;
                    System.Byte[]                               reportBytes = new System.Byte[0]();
                    SRSProxy                                    srsProxy;
                    SRSReportRunService                         srsReportRunService = new SrsReportRunService();
                    Map                                         reportParametersMap;
                    SRSReportExecutionInfo                      executionInfo = new SRSReportExecutionInfo();
    
                    controller.parmReportName(ssrsReportStr(DTPackingSlipNotInvoice , PrecisionDesign1));
                 
                    controller.parmShowDialog(false);
                    controller.parmLoadFromSysLastValue(false);
                 
                    settings = controller.parmReportContract().parmPrintSettings();
                    settings.printMediumType(SRSPrintMediumType::File);
                    settings.fileName(fileName);
                    settings.fileFormat(SRSReportFileFormat::PDF);
                    // Below is a part of code responsible for rendering the report
                    controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
                    controller.parmReportContract().parmReportExecutionInfo(executionInfo);
    
                    srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
                    srsReportRunService.preRunReport(controller.parmreportcontract());
                    reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
                    parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
                    srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
    
                    // Actual rendering to byte array
                    reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),parameterValueArray,settings.fileFormat(),settings.deviceinfo());
                    container binData;
                    Binary binaryData;
                    System.IO.MemoryStream mstream = new System.IO.MemoryStream(reportBytes);
                    binaryData = Binary::constructFromMemoryStream(mstream);
                    if(binaryData)
                    {
                        binData = binaryData.getContainer();
                    }
                    System.Byte[] binData1;
                    System.IO.Stream stream1;
                    // Turn the Bytes into a stream
                    for(int i = 0; i < conLen(binData); i++)
                    {
                        binData1 = conPeek(binData,i+1);
                        stream1 = new System.IO.MemoryStream(binData1);
                    }
    
                    var messageBuilder = new SysMailerMessageBuilder();
                    messageBuilder.addTo(_contract.parmTo()).setSubject(_contract.parmsubject()).setBody(_contract.parmbody());
                    if (stream1 != null)
                    {
                        messageBuilder.addAttachment(stream1, strFmt('%1_%2',any2Str(today()),fileName));
                    }
                    // sends non interactive message
                    SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(messageBuilder.getMessage());
        }
    
    }
    can you please guide me hoi can i pass the filter records to get desired output
     
    thanks ,
    Regards ,
    Dinesh 
  • Suggested answer
    Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    As you can see in your "service" class, you are passing the _contract, but you are not using it.

    So you need to get the query from the contract and apply your logic, here's  an example:
     
    Table1   table1;
    Table2 table2;
    Query query    = _contract.getQuery(); QueryRun queryRun = new QueryRun(query);
    ​​​​​​​ while(queryRun.next()) {     table1 = queryRun.get(tableNum(Table1));     table2 = queryRun.get(tableNum(Table2)); //add logic needed }
    I'm not sure what tables your query contains and how many tables are you interested in
    also if you are interested in other variables in your contract, then you need to get them

    Thanks,
    Layan Jweihan
  • Dineshkarlekar Profile Picture
    1,836 on at
    Hi ,
    Thanks For  Reply ,
    Actuall i have created the view which and it is having relation with hcm worker recid , and the report which is mention in service class is is also using the view so how do i need to mension the view so i get the desired result because only hcm worker wont work , and also i need to tell you that the my query in contract is having the hcm worker as datasource and range of personal number and no table other than that , please suggest me what i have to do next , my code is below .
    final class DTPackingSlipNotInvoicedBatchService  extends SysOperationServiceBase
    {
        public void processoperation(DTPackingSlipNotInvoicedBatchContract  _contract)
        {  
               HcmWorker         hcmWorker;
               Query    query    = _contract.getQuery();
               QueryRun queryRun = new QueryRun(query);
               
           
               while(queryRun.next())
            {
                hcmWorker = queryRun.get(tableNum(HcmWorker));
              
                Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
                Filename                                    fileName = "OpenTransaction_"+ "_contract.parmTo" + ".pdf";
                SrsReportRunController                      controller = new SrsReportRunController();
                SRSPrintDestinationSettings                 settings;
                Array                                       arrayFiles;
                System.Byte[]                               reportBytes = new System.Byte[0]();
                SRSProxy                                    srsProxy;
                SRSReportRunService                         srsReportRunService = new SrsReportRunService();
                Map                                         reportParametersMap;
                SRSReportExecutionInfo                      executionInfo = new SRSReportExecutionInfo();
    
                controller.parmReportName(ssrsReportStr(DTPackingSlipNotInvoice , PrecisionDesign1));
              
                controller.parmShowDialog(false);
                controller.parmLoadFromSysLastValue(false);
                settings = controller.parmReportContract().parmPrintSettings();
                settings.printMediumType(SRSPrintMediumType::File);
                settings.fileName(fileName);
                settings.fileFormat(SRSReportFileFormat::PDF);
                // Below is a part of code responsible for rendering the report
                controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
                controller.parmReportContract().parmReportExecutionInfo(executionInfo);
    
                srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
                srsReportRunService.preRunReport(controller.parmreportcontract());
                reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
                parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
                srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
    
                // Actual rendering to byte array
                reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),parameterValueArray,settings.fileFormat(),settings.deviceinfo());
                container binData;
                Binary binaryData;
                System.IO.MemoryStream mstream = new System.IO.MemoryStream(reportBytes);
                binaryData = Binary::constructFromMemoryStream(mstream);
                if(binaryData)
                {
                    binData = binaryData.getContainer();
                }
                System.Byte[] binData1;
                System.IO.Stream stream1;
                // Turn the Bytes into a stream
                for(int i = 0; i < conLen(binData); i++)
                {
                    binData1 = conPeek(binData,i+1);
                    stream1 = new System.IO.MemoryStream(binData1);
                }
    
                var messageBuilder = new SysMailerMessageBuilder();
                messageBuilder.addTo(_contract.parmTo()).setSubject(_contract.parmsubject()).setBody(_contract.parmbody());
                if (stream1 != null)
                {
                    messageBuilder.addAttachment(stream1, strFmt('%1_%2',any2Str(today()),fileName));
                }
                // sends non interactive message
                SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(messageBuilder.getMessage());
            }
        }
    
    }
     
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    Sorry what is the view you are talking about? I can't see it in code? where do you need to use it?
    can you please explain what you are trying to do from a business point of view?
    Also i can see that you got the hcmWorker from your query but u didn't use it later, so how it's going to work and get desired data if you don't use it.

    Thanks,
    Layan Jweihan
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    sorry for the confusion , i just need to use the hcm worker , but hot to put the range of the filter fields i am not getting , below is my code let me know what i have to make change .
    below is my code .
    final class DTPackingSlipNotInvoicedBatchService  extends SysOperationServiceBase
    {
        public void processoperation(DTPackingSlipNotInvoicedBatchContract  _contract)
        {  
               HcmWorker         hcmWorker;
               DTPackingSlipNotInvoiceView   pkgSlipNotInvoice;
               Query            query;
               QueryRun         queryRun;
               QueryBuildDataSource     qbdshcmWorker;
    
               query    = _contract.getQuery();
    
               qbdshcmWorker =  query.dataSourceTable(tableNum(HcmWorker));
    
               queryRun = new QueryRun(query);
           
               hcmWorker = queryRun.get(tableNum(HcmWorker));
    
        
                    Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
                    Filename                                    fileName = "PackingSlipNotInvoice_"+ "Team" + ".pdf";
                    SrsReportRunController                      controller = new SrsReportRunController();
                    SRSPrintDestinationSettings                 settings;
                    Array                                       arrayFiles;
                    System.Byte[]                               reportBytes = new System.Byte[0]();
                    SRSProxy                                    srsProxy;
                    SRSReportRunService                         srsReportRunService = new SrsReportRunService();
                    Map                                         reportParametersMap;
                    SRSReportExecutionInfo                      executionInfo = new SRSReportExecutionInfo();
    
                    controller.parmReportName(ssrsReportStr(DTPackingSlipNotInvoice , PrecisionDesign1));
    
                    controller.parmShowDialog(false);
                    controller.parmLoadFromSysLastValue(false);
                    settings = controller.parmReportContract().parmPrintSettings();
                    settings.printMediumType(SRSPrintMediumType::File);
                    settings.fileName(fileName);
                    settings.fileFormat(SRSReportFileFormat::PDF);
                    // Below is a part of code responsible for rendering the report
                    controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
                    controller.parmReportContract().parmReportExecutionInfo(executionInfo);
    
                    //controller.startOperation();
    
                    srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
                    srsReportRunService.preRunReport(controller.parmreportcontract());
                    reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
                    parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
                    srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
    
                    // Actual rendering to byte array
                    reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),parameterValueArray,settings.fileFormat(),settings.deviceinfo());
                    container binData;
                    Binary binaryData;
                    System.IO.MemoryStream mstream = new System.IO.MemoryStream(reportBytes);
                    binaryData = Binary::constructFromMemoryStream(mstream);
                    if(binaryData)
                    {
                        binData = binaryData.getContainer();
                    }
                    System.Byte[] binData1;
                    System.IO.Stream stream1;
                    // Turn the Bytes into a stream
                    for(int i = 0; i < conLen(binData); i++)
                    {
                        binData1 = conPeek(binData,i+1);
                        stream1 = new System.IO.MemoryStream(binData1);
                    }
    
                    var messageBuilder = new SysMailerMessageBuilder();
                    messageBuilder.addTo(_contract.parmTo()).setSubject(_contract.parmsubject()).setBody(_contract.parmbody());
                    if (stream1 != null)
                    {
                        messageBuilder.addAttachment(stream1, strFmt('%1_%2',any2Str(today()),fileName));
                    }
                    // sends non interactive message
                    SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(messageBuilder.getMessage());
            
        }
    
    }
     
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    Again can you please explain what you are trying to do from a business point of view? what does the code you sent us do?

    You say that you want to use hcmWorker in filters, but where do you want to use it? for example I can see that you are using the "subject" parameter to fill the email subject. But what do you want to do with hcmWorker?


    Thanks,
    Layan Jweihan
  • Dineshkarlekar Profile Picture
    1,836 on at
    I will be sending the details of selected worker from hcm worker to the _contract.parmTo()  which is email field . i need to pass the filtered personal number to this code for generating the email for the selected worker .
     
    thanks , 
    regards ,
    Dinesh
  • Suggested answer
    Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    why do you need  "_contract.Toparamter()" if you want to get the email from HcmWorker that you've put in query filter?
     
    How does this service class gets called? is it a menu item that you click where you put your filters. Or do you select some fields from a grid?

    But in general, if you take the value of hcmWorker from queryRun, Then you can get the email value from "logisticsElectronicAddress.Locator"
     
    hcmWorker = queryRun.get(tableNum(HcmWorker));
    
    dirPartyTable              dirPartyTable;
    LogisticsElectronicAddress logisticsElectronicAddress;
    
    select firstonly dirPartyTable where hcmWorker.Person ==  dirPartyTable.RecId
    join logisticsElectronicAddress where logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactEmail


    Thanks,
    Layan Jweihan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans