Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to get E-Mail from BatchJob-Report PrintDestinationSettings in AX 2012

(1) ShareShare
ReportReport
Posted on by 38
Hello fellow AX Users and Developers!
 
In our AX 2012 environment, we have set up multiple batch jobs (for each customer) to run the CustTransOpen report. Each customer has their own email address to which the report should be sent. However, the email addresses are currently only available in the PrintDestinationSettings of the BatchJob. We would like to parameterise these in the CustTable to make it easier to adjust the email addresses. For the initial filling, however, I first have to export the e-mail addresses from the BatchJobs/PrintDestinationSettings, which I am struggeling with. Do you have any ideas or tips on how I should approach this?
 
Many thanks and kind regards
  • Verified answer
    erpdell Profile Picture
    38 on at
    How to get E-Mail from BatchJob-Report PrintDestinationSettings in AX 2012
    This is the job I wrote & used:
     
    static void ExpBatchJobPrintDestinationSettingsMail(Args _args)
    {
        //Job data
        Batch               batchTable;
        BatchParameters     batchParameters;
        container           innerCon, conEmailTo, conEmailCC, conEmailSubject, conEmailBcc, conEmailReplyTo;
        //For export file
        TextIo              exportFile;
        FileName            exportFileName;
        int                 counter = 0;
        #File
        #define.CRLF("\r\n")
    
        //Prepare export csv
        exportFileName = @"\\yourPath\"; //File path
        exportFile = new TextIo(exportFileName, #io_write);
        exportFile.outFieldDelimiter(';');
        exportFile.outRecordDelimiter(#CRLF);
        
        //Write header
        exportFile.write("emailSubject;emailTo;emailCC;emailBcc;emailReplyTo");
        
        //Job 
        while select batchTable where batchTable.Caption LIKE "D*" //Query as you need
        {
            counter++;
            //Reset containers, just to make sure we dont export data from the last record
            batchParameters = conNull();
            innerCon = conNull();
            conEmailTo = conNull();
            conEmailCC = conNull();
            conEmailSubject = conNull();
            conEmailBcc = conNull();
            conEmailReplyTo = conNull();
            
            //Iterate batchParameters containers. NOTE: the 2nd parameters (integers) 'where to peek' may differ, depending on custom fields
            batchParameters=batchTable.Parameters;
            innerCon = conPeek(batchParameters, 5); 
            innerCon = conPeek(innerCon, 7); 
            innerCon = conPeek(innerCon, 2); 
            innerCon = conPeek(innerCon, 2); //DataContractMap
            innerCon = conPeek(innerCon, 6); //SRSPrintDestinationSettings
        
            conEmailTo = conPeek(innerCon, 7); 
            conEmailCC = conPeek(innerCon, 5);
            conEmailSubject = conPeek(innerCon, 6);
            conEmailBcc = conPeek(innerCon, 12); //Custom field
            conEmailReplyTo = conPeek(innerCon, 13); //Custom field
            
            exportFile.write(strFmt("%1;%2;%3;%4;%5",
                conPeek(conEmailSubject, 2),
                conPeek(conEmailTo, 2),
                conPeek(conEmailCC, 2),
                conPeek(conEmailBcc, 2),
                conPeek(conEmailReplyTo, 2)));
        }
        
        info(strFmt("Exported %1 records", counter));
    }
     
  • Verified answer
    erpdell Profile Picture
    38 on at
    How to get E-Mail from BatchJob-Report PrintDestinationSettings in AX 2012
    Okay, this seems to be relatively straightforward. I had a look at the 'Batch' and 'BatchJob' tables and on the 'Batch' table there is a "Parameters" field which contains all the parameters in a container structure. I opened it in the debugger and searched for all the required fields, so I'll just loop through them now. I couldn't actually find the customer number in the parameters, luckily it's in the BatchJob description and in the emailSubject. I'll share the job afterwards.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,004 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans