Reading Infologs and Inserting new line for email body Dynamics ax 2012

I have designed a feature where i need to send the executions logs of Batch on its completion via email, That part is done perfectly fine and emails starts coming, I have read the infologs and concatenate the two strings so i can make one big string of multiple infologs, i was using \n between two strings but when i call the email sending code and pass the string; The new lines are not coming to email. The format for sending email was HTML.

i came to know that for HTML format. White spaces such as line-breaks are suppressed in HTML; and we have to use tags like <p> or <br />.

I have also pasted sample code on how i am reading the infologs and added <br/> tag for line break.


 private str 5000 readInfoLog()  
 {  
   SysInfologEnumerator enumerator;  
   SysInfologMessageStruct msgStruct;  
   Exception exception;  
   str 5000 Message;  
   enumerator = SysInfologEnumerator::newData(infolog.copy(1,infologLine()));  
   while (enumerator.moveNext())  
   {  
   msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());  
   exception = enumerator.currentException();  
   message = message + strFmt("Type: %1; Message: %2",  
   exception,  
   msgStruct.message()) + '<br /> ';  
   }  
   return Message;  
 }  

Thanks
Happy Daxing

Advertisements

SSRS Report – Timeout error for Long running queries in AX2012

“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond”

To change the report to run in this pre-processing way (Similar to Sales confirmation, Sales Invoice, etc. reports).
see this example below for the Fixed Asset movement report on how to change this:

1. To find which object you need to modify, first look in the AOT >> Menus, for the Menu where the report is
2. View the properties on this to see the associated menu item. You can see below the menu item is “AssetBalancesPeriod”.

3. Find this menu item in AOT >> Menu Items >> Output and look at the properties, make a note of the “LinkedPermissionObject”, in this case “AssetBalancesPeriod”

4. Next in the AOT >> SSRS Reports >> Reports, locate AssetBalancesPeriod, then expand this out until you see the Server Methods. Make a note of the Server Method class, in this case “AssetBalancesPeriodDP”

5. In the AOT >> Classes, locate and open class AssetBalancesPeriodDP.

6. In the AssetBalancesPeriodDP\classDeclaration, change the extend class to SrsReportDataProviderPreProcess instead of SrsReportDataProviderBase

7. Make a note of the Temp table used in the report, as above this is AssetBalancesPeriodTmp.

8. Next, change the method AssetBalancesPeriodDP\processReport to add the following line after the contract:
contract.parmFromDate();
contract.parmtodate();
AssetBalancesPeriodTmp.setConnection(this.parmUserConnection());

9. Next, in AOT > Data Dictionary > Tables, locate the table you made a note of in point 7, so in this case the AssetBalancesPeriodTmp. Change the table properties as follows:

• TableType = Regular

• CreatedBy = Yes

• CreatedTransactionId = Yes

10. Opened AssetBalancesPeriod report in Visual Studio and refreshed the data source to include new field (CreatedTransactionId).

11. Deployed the new AssetBalancesPeriod report.

12. In AX did a Generate Incremental CIL.

13. Restart SSRS

Now this report can run without timeout error.

Dynamics ax 2012 Use of JSON

I’ve recently had a requirement to integrate an external system with Dynamics AX 2012’. Here is a very basic code sample of how to consume JSON using these classes in Dynamics AX 2012.

 static void myJob(Args _args)  
 {   
   RetailWebRequest request;   
   RetailWebResponse response;   
   str rawResponse, value;   
   Map data;   
   RetailCommonWebAPI webApi = RetailCommonWebAPI::construct();   
   request = RetailWebRequest::newUrl("http://mysite.com/jsonaction");   
   response = webApi.getResponse(request);   
   rawResponse = response.parmData();   
   data = RetailCommonWebAPI::getMapFromJsonString(rawResponse);   
   value = data.lookup("elementname");   
   info(strFmt("Element name: %1",value));   
 }  

Thanks

Happy Daxing 🙂

cannot create a data definition language command on “source document line” : Accounting distribution

error “cannot create a data definition language command on “source document line””

In one of the client we had the requirement to always post the Pending vendor invoice on today’s date, regardless of when it was created. so we did the simple customization to update the TransDate before code initiate the posting process.

vendInvoiceInfoTable.selectForUpdate(true);
vendInvoiceInfoTable.TransDate = today();
vendInvoiceInfoTable.update();

But for this requirement is not that simple, somehow it is not updating the Accounting distribution and keeping the entries on older date in AccountingDistribution table, hence causing the error which is title of this blog.

After lots of investigation i reached to the conclusion, and this small job help me finding the cause and fixing it by creating the new Accounting Distribution record in today’s date and deleting the older one.

 static void VendInvAccDistributionCorrection(Args _args)  
 {  
   AccountingDistribution AccountingDistribution, AccountingDistributionCopy;  
   vendInvoiceInfoLine vendInvoiceInfoLine;  
   VendInvoiceInfoTable vendinvoiceInfoTable;  
   select firstonly vendInvoiceInfoTable where vendInvoiceInfoTable.Num == '1234';// todo invoice number to remove the matching  
   if (vendInvoiceInfoTable.RecId)  
   {  
     ttsBegin;  
     vendInvoiceInfoTable.selectForUpdate(true);  
     vendInvoiceInfoTable.TransDate = today();  
     vendInvoiceInfoTable.update();  
     ttsCommit;  
     while select vendInvoiceInfoLine  
       where vendInvoiceInfoLine.TableRefId == vendinvoiceInfoTable.TableRefId  
         && vendInvoiceInfoLine.ParmId == vendinvoiceInfoTable.ParmId  
     {  
       select firstOnly * from AccountingDistributionCopy order by number desc  
         where AccountingDistributionCopy.SourceDocumentHeader == vendinvoiceInfoTable.SourceDocumentHeader  
           && AccountingDistributionCopy.SourceDocumentLine == VendInvoiceInfoLine.SourceDocumentLine;  
       AccountingDistribution.SourceDocumentLine = VendInvoiceInfoLine.SourceDocumentLine;  
       AccountingDistribution.SourceDocumentHeader = vendinvoiceInfoTable.SourceDocumentHeader;  
       AccountingDistribution.TransactionCurrency = VendInvoiceInfoTable.CurrencyCode;  
       AccountingDistribution.LedgerDimension = AccountingDistributionCopy.LedgerDimension;  
       AccountingDistribution.AccountingLegalEntity = AccountingDistributionCopy.AccountingLegalEntity;  
       AccountingDistribution.MonetaryAmount = AccountingDistributionCopy.MonetaryAmount;  
       AccountingDistribution.AccountingDate = today();  
       if (vendInvoiceInfoLine.LineAmount && AccountingDistribution.MonetaryAmount)  
       {  
         AccountingDistribution.AllocationFactor = AccountingDistribution.TransactionCurrencyAmount/VendInvoiceInfoLine.LineAmount;  
       }  
       else  
       {  
         AccountingDistribution.AllocationFactor = 1;  
       }  
       AccountingDistribution.AmountSource = DistributionAmountSource::PrimaryAmount;  
       //axAccountingDistribution.parmMonetaryAmountType(MonetaryAmount::ExtendedPrice);  
       AccountingDistribution.insertAccountingDistribution(true);  
     }  
       delete_from accountingDistribution  
       where accountingDistribution.SourceDocumentHeader == vendinvoiceInfoTable.SourceDocumentHeader  
       && accountingDistribution.AccountingDate != today();  
   }  
   else{  
     info(strFmt('invoice not found in %1 company', curext()));  
   }  
 }  
%d bloggers like this: