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, ...
Answered

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

(1) ShareShare
ReportReport
Posted on by 48
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
I have the same question (0)
  • Suggested answer
    CU28041408-0 Profile Picture
    48 on at
    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.
  • Verified answer
    CU28041408-0 Profile Picture
    48 on at
    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));
    }
     

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
Abhilash Warrier Profile Picture

Abhilash Warrier 677 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 339 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans