JavaScript in Power Platform – Frequently Asked Interview Questions.
Hello Guys,
In our previous blog, we discussed some useful tips to prepare for interviews on Business Rules. Today, we will look at some important JavaScript tips and interview questions related to Dynamics 365 CRM.
Do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.
The client API object model for model driven apps provides you objects and methods that you can use to apply custom business logic in model driven app using JavaScript. These includes:
- Gets or sets attribute value.
- Show and hide user interface elements.
- Reference multiple controls per attribute.
- Access multiple forms per entity.
- Manipulate form navigation items.
- Interact with the business process flow control.
- Go to Solutions in Dynamics 365
- Select your solution
- Add a Web Resource
- Upload the account_form.js file
- Save and publish
- Open the required Form (e.g., Account Main Form)
- Go to Form Properties
- Add the JavaScript Web Resource
- Ensure Enabled for the form is checked
- Select the required event (OnLoad, OnSave, OnChange)
- Choose the function name (e.g., BLG.accountOnload)
- Check "Pass execution context as first parameter"
Yes, we can make HTTP requests using CRM REST Builder, which generates JavaScript code for XMLHttpRequest. In this approach, you can choose whether the request is synchronous or asynchronous.
For example, in XMLHttpRequest, the third parameter of open() controls this:
req.open("GET", url, false);
17. How to call Power Automate Flow using JS?
var req = new XMLHttpRequest();
req.open("POST", Flowurl, true); // async call
req.setRequestHeader("Content-Type", "application/json");
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status === 200 || req.status === 202) {
console.log("Flow executed successfully", req.responseText);
} else {
console.error("Flow execution failed", req.statusText);
}
}
};
var data = JSON.stringify({ accountId: "00000000-0000-0000-0000-000000000000" });
req.send(data);
18. I have a JavaScript function registered on the OnSave event of a form. However, whenever I create a new record, this function is being triggered unexpectedly. What could be the possible reason?
It’s possible that we are calling a function on the OnLoad event that contains the code formContext.data.entity.save(). Since this programmatically saves the record as soon as the form loads, it triggers the OnSave event, even for new records. That’s why the OnSave function runs unexpectedly. To avoid this, we should either avoid calling save() on load or add proper checks for the form type and save mode so that it doesn’t execute on new records or during autosave.
19. how to skip AutoSave in JS?
function onSaveHandler(executionContext) {
var saveEvent = executionContext.getEventArgs();
var saveMode = saveEvent.getSaveMode();
// Skip AutoSave (saveMode 70 = Save & Close, 58 = AutoSave)
if (saveMode === 58) return;
// Your code here
}

Comments
Post a Comment