Thursday, January 16, 2025

Day 23: Creating New Records Programmatically with JavaScript in Dataverse / MSCRM



In this Blog, we will see how to Create New Records Programmatically with JavaScript in Dataverse / MSCRM

var record = {};
record.bosch_dayname = "Name of the Record"; // Text

Xrm.WebApi.createRecord("bosch_day", record).then(
	function success(result) {
		var newId = result.id;
		console.log(newId);
	},
	function(error) {
		console.log(error.message);
	} );


You can pass different parameter based in the "record" to create with field values

Wednesday, January 15, 2025

How to Retrieve Records using FETCHXML using JavaScript in MSCRM or Dataverse

In this blog we will see how to How to Retrieve Records using FETCHXML using JavaScript in MSCRM or Dataverse


1. Prepare FetchXML ( Login to CRM or Dataverse then Go to Advance Find and Frame your Query and Download the FetchXML)
2. Consider am retrieving All Accounts

function retriveRecordusingFetchXML() {
    var fetchXml = `
<fetch>
  <entity name="account">
    <attribute name="accountid" />
    <attribute name="name" />
  </entity>
</fetch>`;

    var encodedFetchXML = encodeURIComponent(fetchXml);
    var fetchXmlRequest = "?fetchXml=" + encodedFetchXML;
    Xrm.WebApi.retrieveMultipleRecords("account", fetchXmlRequest).then(
        function success(result) {
            for (const record of result.entities) {
                var name = record.name;
            }
        },
        function (error) {
            var alertMessage = { text: error.message };
            Xrm.Navigation.openAlertDialog(alertMessage, null);
        }
    );
}

Use the Above Code to retrieve Record 

you can change the FetchXML based on your requirement.

Tuesday, January 7, 2025

Day 22: Fetching Records with Xrm.WebApi.retrieveRecord in Dataverse / MSCRM

 In this Blog we will see how to Use Xrm.WebApi.retrieveRecord in Dataverse / MSCRM



function retreiveRecord(executionContext) {
    var formContext = executionContext.getFormContext();
    var getCurrentRecordid = formContext.data.entity.getId();
    getCurrentRecordid = getCurrentRecordid.replace("{", "").replace("}", "");
    Xrm.WebApi.retrieveRecord("TABLENAME", getCurrentRecordid , "?$select=fieldname1,fieldname2").then(
        function success(result) {
            console.log(result);
            // Columns
            var bosch_dayid = result["fieldname1"]; 
            var bosch_dayname = result["fieldname2"]; 
        },
        function (error) {
            console.log(error.message);
        }
    );
}

Day 23: Creating New Records Programmatically with JavaScript in Dataverse / MSCRM

In this Blog, we will see how to Create New Records Programmatically with JavaScript in Dataverse / MSCRM var record = {}; record.bosch_day...