CRM 2016 + JavaScript: Web Resource cannot be reloaded

Since we got upgraded to CRM 2016 from CRM 2015, we faced a strange issue with JavaScript and Web Resource (html).

At some point of time the script goes to reload the html Web Resource with the following code:

var webResource = Xrm.Page.getControl("WebResource_ControlName");

Easiest way to reload the web resource!

But the same code does not work in case of CRM 2016. As the web resource was already loaded when the page was loaded. CRM 2016 treats the same web resource not to be loaded again (may be for better performance!).

After trying numerous ways to solve, following code worked perfectly:

var webResource = Xrm.Page.getControl("WebResource_ControlName");
webResource.setSrc(Xrm.Page.context.getClientUrl() + "/WebResources/new_webResource?data=someValue%26ver%3D" + Math.random());

Here, I had to pass some parameters. What I have done to modify is added another parameter called “ver” (you can have any other parameter name instead of “ver”) and the value will be rendered from Math.random() method. This way the web browser treats each URL as a new request as Math.random() will return random number each time it will be executed.


CRM 2011, JavaScript: How to add some action after save record?

Hi there!

I recently had a requirement where I had to save the record and open another form once the button is pressed from ribbon.

I added the save JavaScript to the web resource and call it and call other function to open the form. This was not working for me.

Resolution for this:

Add an event on Save action by:; // openAccountForm is another function which opens the form;
function openAccountForm() {

CRM 2011 + JavaScript: Get Id of the current record

Get the current record’s Id from the following function:;

CRM 2011: Set Due Date to today and Due Time to 08:00 AM by default

Hello everyone…

Recently I was asked a question:
Can we load current date and time (8 AM default) to Due field in activities in Microsoft Dynamics CRM 2011?
I got the solution… yeah!!

For this you need to edit the activity (Task/Phone Call/Fax/Email/etc.) entity and put a JavaScript in OnLoad event of the entity form.

My First try was to access both date and time through HTML DOM with very easy JavaScript code…

document.getElementById("dateInput").value = currentDate;
document.getElementById("timeInput").value = "08:00";

But, it created a problem; when the date field was edited by the user, the time would change to 00:00 by default. I searched many blogs and finally found an attribute called scheduledend which can be accessed through Xrm.Page object and getAttribute() method. Just need to set a JavaScript date and you have the values desired in Due Date and Time fields.

Here is the script I wrote to populate date and time:

var d = new Date();
var date = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 8, 0, 0, 0);

Here is the result when a new activity is created:

Rikin Shah.