CRM Crate

Generate XML data of an entity record using getDataXML in Dynamics 365

We will learn to generate XML data of an entity record in Dynamics 365. Before we start, make sure to subscribe to CRM Crate so that you stay up-to-date in field of Dynamics 365.

Generate XML data of an entity record in Dynamics 365

What is XML?

XML stands for eXtensible Markup Language. It is a markup language much like HTML which has been designed to store and transport data.

The XML above is quite self-descriptive:

  • It has sender information.
  • It has receiver information
  • It has a heading
  • It has a message body.

As a conclusion, the XML is just information wrapped in tags.

How to generate XML data of an entity record in Dynamics 365?

Whenever a record is saved in Dynamics 365, the data is been sent to the server in the form of XML. We will utilize the getDataXML client reference API to get the XML data sent to the server while saving the record.

formContext.data.entity.getDataXml();

Returns a string representing the XML that will be sent to the server when the record is saved. Only data in columns that have changed or have their submit mode set to “always” are sent to the server.

JavaScript snippet code to retrieve the XML data –

The below JavaScript function is triggered during the OnChange event of the record’s field.

//CRM Crate - JavaScript Snippet
function CallMethod (executionContext) {

//Reading Attribute Value From The Form.
var formContext = executionContext.getFormContext();
var Input = formContext.getAttribute("cc_input").getValue() != null ? formContext.getAttribute("cc_input").getValue() : null;

//Validating Form Field Conditions.
if(Input == true)
{

//Using getDataXML Client API.
var XMLData = formContext.data.entity.getDataXml();

//Setting Value In Form's Field.
formContext.getAttribute("cc_xmldata").setValue(XMLData)
}
else
{
formContext.getAttribute("cc_xmldata").setValue("")
}
}

Validate the output in Dynamics 365 –

Once the above JavaScript has been deployed and configured, let us now verify the output in Dynamics 365 form as shown below.

XML Data Output –

<cc_sampleentity><cc_input1>Prashant</cc_input1><cc_input2>Omkar</cc_input2><cc_input3>Priya</cc_input3><cc_input>true</cc_input></cc_sampleentity>

Thus we learned to generate XML data of an entity record using getDataXML in Dynamics 365.

5 1 vote
Article Rating
Subscribe
Notify of

0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.