Category Archives: Microsoft Dynamics AX

C#: Deserializing Json Array using Newtonsoft.Json

Deserializing Json Array using Newtonsoft.Json

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ABJNewtonsoftJson
{
public class Program
{
static void Main(string[] args)
{
string json = @”{‘lines’:[
{‘RecId’:35637332944,’LineNumber’:1,’ItemId’:’VH001′,’ReceivedQty’:2},
{‘RecId’:35637332945,’LineNumber’:2,’ItemId’:’VH002′,’ReceivedQty’:6},
{‘RecId’:35637332946,’LineNumber’:3,’ItemId’:’VH003′,’ReceivedQty’:8},
{‘RecId’:35637332947,’LineNumber’:4,’ItemId’:’VH004′,’ReceivedQty’:9},
{‘RecId’:35637332948,’LineNumber’:5,’ItemId’:’VH005′,’ReceivedQty’:1}]}”;
//PurchLineData purchLineData = JsonConvert.DeserializeObject<List<PurchLineData>>(json);

PurchLineDataList purchLineDataList = JsonConvert.DeserializeObject<PurchLineDataList>(json);

for (var i = 0; i < purchLineDataList.lines.Count; i++)
{
Console.WriteLine(“RecId : {0}”, purchLineDataList.lines[i].RecId);
Console.WriteLine(“LineNumber : {0}”, purchLineDataList.lines[i].LineNumber);
Console.WriteLine(“ItemId : {0}”, purchLineDataList.lines[i].ItemId);
Console.WriteLine(“ReceivedQty : {0}”, purchLineDataList.lines[i].ReceivedQty);
Console.WriteLine(‘\n’);
}
Console.ReadLine();
}
}

public class PurchLineDataList
{
public List<PurchLineData> lines;
}

public class PurchLineData
{
public Int64 RecId { get; set; }
public int LineNumber { get; set; }
public string ItemId { get; set; }
public int ReceivedQty { get; set; }
}
}

AX 2012 R3: “No device” keep on showing when opening AX clients.

AX 2012 R3: No device showing when opening AX clients.

No device error message shown, when opening Microsoft Dynamics AX 2012 R3 Clients.

1

Check if telephony integration is activated in Licence configuration, if activated deactivate it if not needed.

System Administration > Setup > Licensing > License configuration.

5

Untick and click Apply to deactivate Telephony integration.

2

Click OK to continue.

3

Synchronise to make configuration changes take effect.

4

 

Ariston J.

AX 2012: Error when in SSRS print preview

Error in Microsoft Dynamics AX 2012 Reports Print Preview

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:queryBuilderArgs. The InnerException message was ‘Element ‘http://tempuri.org/:queryBuilderArgs&#8217; contains data from a type that maps to the name ‘http://schemas.datacontract.org/2004/07/XppClasses:SrsReportProviderQueryBuilderArgs&#8217;. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to ‘SrsReportProviderQueryBuilderArgs’ to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.’.  Please see InnerException for more details.

The formatter threw an exception while trying to deserialize the message
Solutions:

Check Inbound Ports in Microsoft Dynamics AX Client.

The formatter threw an exception while trying to deserialize the message - sol

Activate Inbound Ports “BIServices” then try to print reports again.

It also important to activate inbound services as possible.

The formatter threw an exception while trying to deserialize the message - sol 2

 

AX 2012: Convert Base64String to Images File

Convert Base64String to Images files or PNG Files.

In my scenario, I need to read Base64String from other application through web services and save it as images file in my server computer.

 

static void convertBase64ToImages(Args _args)

{

str base64String = ‘XXXXXX-BASE64STIRNG-XXXXXX’;

// Save the image

AifUtil::saveBase64ToFile(@”C:\TEMP\TEST1.PNG”, base64String);

}

 

AX 2012 R3: Purpose in Edit Address Form – Roles and description not showing label text.

Problem: AX 2012 R3: Purpose in Edit Address Form – Roles and description not showing label text.

MS AX Versions: Microsoft Dynamics AX 2012 R3 CU12

The purpose field is showing label id instead of showing the correct label text, like image below:

purpose-roles-and-description-not-showing-label

Did anyone encountered above issues, we will be happy if you can share with us.

 

Wish you the best,

Ariston Javier

 

 

AX 2012: Post Sales Invoice using X++

AX 2012: Post Sales Invoice using X++

static void postSalesInvoice(Args _args)
{
SalesFormLetter salesFormLetter;
SalesTable salesTable;
SalesId salesId = ‘005063’;
System.Exception error;
str strError;
CustInvoiceJour custInvoiceJour;
;

ttsBegin;
try
{
salesTable = SalesTable::find(salesId);

if (salesTable && salesTable.SalesStatus == SalesStatus::Delivered)
{
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No, NoYes::Yes);

if (salesFormLetter.parmJournalRecord().TableId == tableNum(CustInvoiceJour))
{
custInvoiceJour = salesFormLetter.parmJournalRecord();
info(strFmt(‘Sales Order #:%1 has been successfully posted and Invoice #:%2 is created!’, custInvoiceJour.SalesId, custInvoiceJour.InvoiceId));
}

}
else
{
info(strFmt(‘%1 does not exsists or null in the system, please try again!’, salesId));
}

}
catch (Exception::CLRError)
{
error = CLRInterop::getLastException();
strError = error.ToString();

info(strfmt(‘%1’, strError));
info(strFmt(‘%1 failed to post, please try again!’, salesId));
}
ttscommit;
}

AX 2012: Post Packing Slip using X++

AX 2012: Post Packing Slip using X++

static void postPackingSlip(Args _args)
{
SalesFormLetter salesFormLetter;
SalesTable salesTable;
SalesId salesId = ‘SO00001’;
System.Exception error;
str strError;
CustPackingSlipJour custPackingSlipJour;
;

ttsBegin;
try
{
salesTable = SalesTable::find(salesId);

if (salesTable && salesTable.SalesStatus == SalesStatus::Backorder)
{
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::PackingSlip, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No);

if (salesFormLetter.parmJournalRecord().TableId == tableNum(custPackingSlipJour))
{
custPackingSlipJour = salesFormLetter.parmJournalRecord();
info(strFmt(‘New Packing Slip #:%1 successfully created for Sales Order #:%2’, custPackingSlipJour.PackingSlipId, custPackingSlipJour.SalesId));
}
}
else
{
info(strFmt(‘%1 does not exsists or null in the system, please try again!’, salesId));
}

}
catch (Exception::CLRError)
{
error = CLRInterop::getLastException();
strError = error.ToString();

info(strfmt(‘%1’, strError));
info(strFmt(‘%1 failed to delivered, please try again!’, salesId));
}
ttscommit;
}

AX 2012 R3: Convert Images (JPEG) to Base64

How to convert images to base 64

public str (RefRecId _refRecId, RefTableId _refTableId)

{
System.Drawing.Image image;
System.IO.MemoryStream memoryStream;
str filePath = ”;
Filename fileName = ”;
DocuRef docuRef;
;

select docuRef
where docuRef.RefRecId == _refRecId
&& docuRef.RefTableId == _refTableId;

if (docuRef)
{

// Get Images complete File Name
fileName = docuRef.completeFilename();

image = System.Drawing.Image::FromFile(@Filename);
memoryStream = new System.IO.MemoryStream();
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat::get_Jpeg());
filePath = System.Convert::ToBase64String(memoryStream.ToArray());
}

return filePath;
}

Screen Shot:

Capture

 

Note:

Assuming parameters _refRecId and _refTableId came from InventTable where the Product Images is set in Released Product under Product Image function. See image below:

Untitled