Introduction:
Are you a developer working with Dynamics 365 and struggling to keep track of all the essential JavaScript functions and methods? Look no further! In this blog post, we've put together a comprehensive Dynamics 365 JavaScript cheat sheet to streamline your development efforts and help you navigate through the intricacies of working with this powerful CRM platform. Whether you're a seasoned developer or just starting with Dynamics 365, this cheat sheet will be your go-to resource for writing efficient and effective JavaScript code.
1. Retrieving Data
Get a Single Record:
javascriptXrm.WebApi.retrieveRecord(entityName, recordId, options).then(successCallback, errorCallback);
Retrieve Multiple Records:
javascriptXrm.WebApi.retrieveMultipleRecords(entityName, options).then(successCallback, errorCallback);
2. Creating and Updating Records
Create a Record:
Xrm.WebApi.createRecord(entityName, data).then(successCallback, errorCallback);
Update a Record:
javascriptXrm.WebApi.updateRecord(entityName, recordId, data).then(successCallback, errorCallback);
3. Deleting Records
Delete a Record:
javascriptXrm.WebApi.deleteRecord(entityName, recordId).then(successCallback, errorCallback);
4. Working with Option Sets
Get the Option Set Values:
javascriptXrm.WebApi.retrieveOptionSetMetadata(entityName, attributeName).then(successCallback, errorCallback);
Set Option Set Value:
javascriptXrm.Page.getAttribute(attributeName).setValue(optionSetValue);
5. Form Events
OnLoad Event:
javascriptfunction formOnLoad(executionContext) {
// Your code here
}
OnSave Event:
javascriptfunction formOnSave(executionContext) {
// Your code here
}
6. Show/Hide and Enable/Disable Controls
Show a Control:
javascriptXrm.Page.getControl(controlName).setVisible(true);
Hide a Control:
javascriptXrm.Page.getControl(controlName).setVisible(false);
Enable a Control:
javascriptXrm.Page.getControl(controlName).setDisabled(false);
Disable a Control:
javascriptXrm.Page.getControl(controlName).setDisabled(true);
7. Working with Web Resources
Get Web Resource URL:
javascriptvar webResourceUrl = Xrm.Page.context.getClientUrl() + "/WebResources/<web_resource_name>";
8. Form Notifications
Show Success Notification:
javascriptXrm.Page.ui.setFormNotification("Record saved successfully.", "INFO", "successNotification");
Show Error Notification:
javascriptXrm.Page.ui.setFormNotification("An error occurred while processing your request.", "ERROR", "errorNotification");
Conclusion: This Dynamics 365 JavaScript cheat sheet provides a quick reference to some of the most commonly used functions and methods when working with Dynamics 365. Whether you're building custom workflows, implementing business rules, or enhancing the user experience, mastering these JavaScript snippets will streamline your development process and make you a more efficient Dynamics 365 developer.
Remember, this is just a starting point, and the possibilities with Dynamics 365 and JavaScript are vast. Always refer to the official Microsoft Dynamics 365 documentation for more in-depth information and stay updated with the latest releases.
Happy coding!