Get Data sent to server on Save using Dynamics 365 CRM JavaScript | GetDataXML function

Now, in case you are working on forms in Dynamics 365 CRM, and you want to know what all data is changed – There are 2 ways to get this

Scenario

Let’s look at the below scenario where this is useful –

  1. You have a record which you are about to Edit. This is how it looks as of now.

  2. Now, I have an OnSave event on which I’m calling a function to capture what all is being saved.

  3. Now, below is what I want to change and then click Save to save the changes.

  4. And then click Save. Now, I want to capture all this data upon Saving to know and further process what has been changed. Let’s see how we can achieve this using Dynamics 365 CRM JavaScript

getDataXml() method

Here’s how you will see the data to be changed

  1. Below, you see that I’m using formContext.data.entity.getDataXml(); to get the data that was changed and which will be setn to the server to saving/processing.
    Please note that here, I’ve used formContext as my variable to store the context passed from the Save event on the form.


    Here’s the code for you to copy and change for yourself –  var xmlData = formContext.data.entity.getDataXml();
  2. Now, when I run this on the Dev Tools in the Browser, I can see what is being populated when I save the record.



  3. Once I hit debugger, I’ll get the same in the variable I created.


  4. And when I run this variable in the Console to see the complete data, I get this in XML.


  5. And that’s how you can capture data in Dynamics 365 which is being sent to the server for processing/saving.

Hope this helps!

Here are some Power Automate posts you want to check out –

  1. Select the item based on a key value using Filter Array in Power Automate
  2. Select values from an array using Select action in a Power Automate Flow
  3. Blocking Attachment Extensions in Dynamics 365 CRM
  4. Upgrade Dataverse for Teams Environment to Dataverse Environment
  5. Showing Sandbox or Non Production Apps in Power App mobile app
  6. Create a Power Apps Per User Plan Trial | Dataverse environment
  7. Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
  8. Co-presence in Power Automate | Multiple users working on a Flow
  9. Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
  10. Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
  11. Call a Flow from Canvas Power App and get back response | Power Platform\
  12. FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
  13. Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
  14. Asynchronous HTTP Response from a Flow | Power Automate
  15. Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
  16. Converting JSON to XML and XML to JSON in a Flow | Power Automate

Thank you!

Advertisement

Ribbon button visibility based on a null value in field in Dynamics 365 | Ribbon Workbench

In case you are using ValueRule already for showing / hiding a ribbon button, but wondering how you can check for the same field for null values i.e. showing the ribbon button only when the field contains data?

I’ll explain in this post –

You can also refer this post for showing/hiding button based on a certain value – https://d365demystified.com/2021/01/08/ribbon-button-visibility-based-on-a-field-value-in-dynamics-365-ribbon-workbench/

ValueRule

Let’s consider an example where you want to show a Subscription button based on the Group Code field on the Account form –

  1. I have a Group Code button on the Account Form, if this contains data, only then the Subscription button/flyout button should show.

  2. So, in the Ribbon Workbench, you can select your button and start by adding a Display Rule (Assuming you don’t have other Display Rules already set which you’ll need to take care of)

  3. In the Display Rule, you can select the type as ValueRule

  4. In the value Rule, the field you are checking for in this example is Group Code (Name: cf_groupcode)


    At this point, if I leave the Value as blank in the above screenshot, the button will be hidden if the value is blank in the above shown Display Rule. This acts as Show when “Group Code Does Not Contain Data

    In this case, the button will be shown when the Group Code field is blank.


    And hidden when the Group Code field Contains Data


  5. Now, if we choose to Invert Result, you’ll get this – This will act as Show when “Group Code Contains Data


    Now, in this condition, the Ribbon button will be shown is the Group Code has data in it.


    And will be hidden when the Group Code field is blank.

Also Ensure

If you are wondering if your changes are being applied, also cross check the below two points –

  1. The Command must be attached to the button.

  2. And the DisplayRule must be attached to the Command itself.

Hope this was useful!

Here are some more XrmToolBox related posts which you might want to check –

  1. Create a Flyout menu for ribbons in Ribbon Workbench | XrmToolBox
  2. Show custom ribbon button based on Security Role of the logged in User in Dynamics 365 | Ribbon Workbench in XrmToolbox
  3. Connecting XrmToolBox to an MFA enabled Dynamics 365 environment | Azure AD
  4. Find deprecated JS code used in your Dynamics 365 environment | Dynamics 365 v9 JS Validator tool | XrmToolBox
  5. Delete App Passwords created by other users in Office 365 | Multi-factor authentication
  6. Single record and multiple record auditing in Dynamics 365 to Audit record access | M365 Compliance
  7. Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
  8. Show custom ribbon button based on Security Role of the logged in User in Dynamics 365 | Ribbon Workbench in XrmToolbox
  9. Ribbon button visibility based on a field value in Dynamics 365 | Ribbon Workbench
  10. Get GUID of the current View in Dynamics 365 CRM JS from ribbon button | Ribbon Workbench
  11. Pass Execution Context to JS Script function as a parameter from a Ribbon button in Dynamics 365 | Ribbon Workbench

Thank you!

Dynamics 365 JavaScript Client Scripting for Beginners | [Video Series]

Hi! If you are a newbie to Dynamics 365 JavaScript, I’ve made a short series on the same from a Beginner’s perspective.

I’ll keep enriching this series with advanced topics soon.

Pre-Requisites

In order to be able to start JavaScript form scripting for Dynamics 365 CRM / Model-Driven Apps, you must have the below –

  1. Beginner to moderate JavaScript knowledge
  2. Visual Studio or Visual Studio Code
  3. System Customizer / System Admin access to the Dynamics 365 / Model-Driven environment.

Also, for complete reference to Dynamics 365 Client Scripting, here’s the official Microsoft Documentation on the same – https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference?WT.mc_id=DX-MVP-5003911

YouTube Videos

Hope this was useful. In order to also look for a beginner series on writing Plugins for Dynamics 365 CRM / Dataverse, I’ve created a Blog Series for the same as well – Plugins Development in Dynamics 365 CRM for Beginners | [Blog Series]


Hope this is a helpful start!
Here are some more Dynamics 365 CE / CRM posts which you might want to check –

  1. Make Managed fields Required in Dynamics 365 – Managed Properties Error [Workaround] | D365 CE Quick Tip
  2. Sign up for a Dynamics 365 Project Operations (Lite Deployment) environment and provision a new instance | Power Platform
  3. Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
  4. Duration field in Dynamics 365 converts Hours value to Days in Dynamics 365 | [Flow Workaround to convert in Hours and Mins]
  5. Show custom ribbon button based on Security Role of the logged in User in Dynamics 365 | Ribbon Workbench in XrmToolbox
  6. Connecting XrmToolBox to an MFA enabled Dynamics 365 environment | Azure AD
  7. Pass Execution Context to JS Script function as a parameter from a Ribbon button in Dynamics 365 | Ribbon Workbench
  8. Pass data to HTML Web Resource using browser’s sessionStorage in Dynamics 365 CE
  9. Form Access Checker in new Power Apps Form Designer | Model-Driven Apps in Dynamics 365
  10. Find deprecated JS code used in your Dynamics 365 environment | Dynamics 365 v9 JS Validator tool | XrmToolBox

Thank you!!