Plugin throw customized error, unsaved changes are on form.

I have got one issue when I change some hidden fields on the CRM form and then I was executing the save code for CRM, on save there was one plugin running that throws some handled error message. Now I only get the “OK” and “Download Log” button.

Once i click OK button i still see some unsaved changes

For that if we don’t want to show the unsaved changes on the form below things we can do.

  1. Either find what are all the fields we have changes and set their initial values once you click the okay button (Note: we don’t have any click event given for this ‘OK’) button.
  2. Or some how set the form dirty = false on close of that pop up. (That is also not possible to achieve as we don’t have click/change event)

Solution for this situation would be as below :

  1. we can use save.then() function like below:

Xrm.Page.data.save().then(function (success) {
//This is success call back , do whatever you want to do. after save is done.
}, function (error) {
Xrm.Page.getAttribute(“FieldUniqueName”).setValue(Xrm.Page.getAttribute(“FieldUniqueName”).getInitialValue());

////Please note this getInitialValue only work for optionset and bool fields.
Xrm.Page.data.setFormDirty(false);
if (error && error.message) {
//This is the section where we get the error.message in the string format, we can show this in the formnotification.
} else {
// show default message if the error.message is empty or undefined.
}
});

Advertisements

‘Go to definition’ failed, either because the caret is already at the definition or because an explicit definition could not be found

In Visual studio if you get this below error. there are below solution we can do.

2017-06-07_0234

first check you code doesn’t have any error.

  1. Solution: If its a microsoft product then restart the program or computer system may help.
  2. open console and run below command.

navigate to the directory which visual studio version you are using.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>devenv.exe / resetuserdata

How to get the current datetime in CRM client side using Javascript.

I got the issue where I needed to get the datetime as per CRM logged in user timezone. I have written one more blog where we can do this at server side by hitting the org service Get date time as per current user time zone , but how to do that at client side??

Either we can hit the CRM services to get the timezone and calculate the time or we have one simple way to do that as below:

What exactly below code does?

This gets the current machine time and then converts the UTC datetime. after that we calculate crm user datetime by adding the current time zone offset minutes of logged in user.

How to get the offset minutes of the login user?

Xrm.Page.context.getTimeZoneOffsetMinutes();

////Please note: This method is available only after “CRM 2015 Update 1” version.

over all code is as below:

var date = new Date();

var utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());

var crmUserDateTime = new Date(utcDate.setMinutes(utcDate.getMinutes() + Xrm.Page.context.getTimeZoneOffsetMinutes()));

We can ever use jQuery date picker and simply pass the date in var date = new Date(“05/25/2017”);

var date = new Date(“05/25/2017”); // here we can pass multiple formated dates. and any date.

var utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());

var crmUserDateTime = new Date(utcDate.setMinutes(utcDate.getMinutes() + Xrm.Page.context.getTimeZoneOffsetMinutes()));

Hope this helps 🙂

Happy learning.

Please follow my blog, so that whenever i create any blog you get notifications.

How to Resize the window.showModelDialog after load of dialog.

Recently I got the requirement where, I had to show the Model dialog in small size and as per some conditions i need to adjust the size of the dialog, for that we need to use below

Resize function or dialogWidth and dialogHeight properties.

In other words dialogWidth and dialogHeight properties can help to adjust the width and height of the dialog. but if we need to do it in percentile increment then first we need to get the previous values and then do the addition and deletion in height and width.

 

Parent Page

<!DOCTYPE html>

<html>

<head>

https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

</head>

<body>

<p>Click the button to open a new browser window.</p>

<button onclick=”myFunction()”>Try it</button>

function myFunction() {

window.showModalDialog(“./dialog.html”, “”, “dialogWidth:600px; dialogHeight:400px; center:yes; resizable:no”);

}

</body>

</html>

Dialog Html

<!DOCTYPE html>

<html>

<head>

https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

$(document).ready(function(){

$(window).resize(function() {

window.dialogWidth = $(window).width() * 2;

window.dialogWidth = $(window).height() * 2;

});

$(window).trigger(‘resize’);

});

</head>

<body>

<p>Open a new window, and resize the width and height to 500px:</p>

</body>

</html>

or try this below html on demand height and width setting.

 

<!DOCTYPE html>

<html>

<head>

https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

function ResizeNow(){

window.dialogWidth = $(window).width() * 2;

window.dialogWidth = $(window).height() * 2;

}

</head>

<body>

<button onclick=”ResizeNow()”>Resize Now</button>

<p>Open a new window, and resize the width and height to 500px:</p>

</body>

</html>

How to Resize the window.showModelDialog after load of dialog.

Recently I got the requirement where, I had to show the Model dialog in small size and as per some conditions i need to adjust the size of the dialog, for that we need to use below

Resize function or dialogWidth and dialogHeight properties.

In other words dialogWidth and dialogHeight properties can help to adjust the width and height of the dialog. but if we need to do it in percentile increment then first we need to get the previous values and then do the addition and deletion in height and width.

 

Parent Page

<!DOCTYPE html>
<html>
<head>
https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
</head>
<body>

<p>Click the button to open a new browser window.</p>

<button onclick=”myFunction()”>Try it</button>

function myFunction() {
window.showModalDialog(“./dialog.html”, “”, “dialogWidth:600px; dialogHeight:400px; center:yes; resizable:no”);
}

</body>
</html>

Dialog Html

<!DOCTYPE html>
<html>
<head>
https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

$(document).ready(function(){

$(window).resize(function() {
window.dialogWidth = $(window).width() * 2;
window.dialogWidth = $(window).height() * 2;
});

$(window).trigger(‘resize’);

});

</head>
<body>

<p>Open a new window, and resize the width and height to 500px:</p>

</body>
</html>

or try this below html on demand height and width setting.

 

<!DOCTYPE html>
<html>
<head>
https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

function ResizeNow(){

window.dialogWidth = $(window).width() * 2;
window.dialogWidth = $(window).height() * 2;
}

</head>
<body>
<button onclick=”ResizeNow()”>Resize Now</button>
<p>Open a new window, and resize the width and height to 500px:</p>

</body>
</html>

Limitations of Microsoft dynamic CRM Word Templates

  1. It cannot Filter/Sort the repeater data.
  2. We can only go up to one level down in context of relationship.
  3. If any of the attribute value is empty then it reserves the place (template looks dirty because of empty spaces)
  4. Repeater Only shows 100 lines( if you have more than 100 contact in account it won’t show)
  5. Once the document is downloaded and later on if you add any new field you have to delete the document and create the new document, As there is no update document option. We need to remap the fields again (here copy paste works that’s one releaf point).

How to fetch Users with Security roles using fetch xml

securityroleswithusername

<fetch mapping=”logical” count=”50″ version=”1.0″ >
<entity name=”systemuser” >
<attribute name=”fullname” />
<link-entity name=”systemuserroles” from=”systemuserid” to=”systemuserid” >
<link-entity name=”role” from=”roleid” to=”roleid” >
<attribute name=”name” />
<attribute name=”roleid” />
</link-entity>
</link-entity>
</entity>
</fetch>

——————————Below fetch can be used in fetch based report———-

<fetch mapping=”logical”>
<entity name=”systemuser” >
<attribute name=”fullname” />
<attribute name=”systemuserid” />
<link-entity name=”systemuserroles” from=”systemuserid” to=”systemuserid” alias=”systemMapping” >
<link-entity name=”role” from=”roleid” to=”roleid” alias=”RoleTable” >
<attribute name=”name” />
<attribute name=”roleid” />
</link-entity>
</link-entity>
</entity>
</fetch>