Archive for the ‘MS CRM 2015’ Category

Auto Create Sharepoint Folder in CRM online

October 2, 2015 11 comments

Many of our customers annoyed and frustrated with popup that appears when they click on documents navigation link on a record to add documents. So I thought it can be easily addressed  using workflow/plugin on create of record by automatically adding the SharePoint location record.But that did not resolve problem still users prompted with popup. When  i googled on this topic i found one post from Scott but that requires to have user name and password of the sharepoint admin.

After lot of trial and error just started with my best friend fiddler to capture request and response that were posted on click of the popup window.  CRM online uses CRM API message “CreateFolder”  to create sharepoint folder and location record. I tried to use this “CreateFolder” message in my custom workflow step to create folder but received error message “This requested can’t be executed in sandbox mode”  then tried with javascript to post same message and it worked fine.

Here is complete script to auto create sharepoint folder for CRM online. Add below script to your script resource file and save  and publish it.  Then call function createDocFolder on onload of the page that will automatically create sharepoint and location folder.

//Function to be called on onload of the page.
var myFormType = null;
function createDocFolder() { () {
            myFormType = Xrm.Page.ui.getFormType();
       if (myFormType === 1 && Xrm.Page.ui.getFormType() !== 1) { // calls this method only when new record is saved.
           var clientUrl = Xrm.Page.context.getClientUrl();
           var xmlhttp = new XMLHttpRequest();
 “POST”, clientUrl + “/XRMServices/2011/Organization.svc/web”, false);
           xmlhttp.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);
           xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
           xmlhttp.setRequestHeader(“SOAPAction”, “”);
           xmlhttp.onreadystatechange = function () {
         if (xmlhttp.readyState == 4 && xmlhttp.status != 200) {
                      alert( xmlhttp.responseText);

//Function to build request

function buildCreateReq() {
var recordId =“{“, “”).replace(“}”, “”);
return “<s:Envelope xmlns:s=\”\”>” +
” <s:Header>” +
” <SdkClientVersion xmlns=\”\”></SdkClientVersion>” +
” </s:Header>” +
” <s:Body>” +
“<Execute xmlns=\”\” xmlns:i=\”\”>” +
” <request i:type=\”b:CreateFolderRequest\” xmlns:a=\”\” xmlns:b=\”\”>” +
” <a:Parameters xmlns:b=\”\”>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>FolderName</b:key>” +
” <b:value i:type=\”c:string\” xmlns:c=\”\”>” + + “_” + recordId + “</b:value>” +
” </a:KeyValuePairOfstringanyType>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>RegardingObjectType</b:key>” +
” <b:value i:type=\”c:int\” xmlns:c=\”\”>” + Xrm.Page.context.getQueryStringParameters().etc + “</b:value>” +
” </a:KeyValuePairOfstringanyType>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>RegardingObjectId</b:key>” +
” <b:value i:type=\”c:string\” xmlns:c=\”\”>” + recordId + “</b:value>” +
” </a:KeyValuePairOfstringanyType>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>DocumentType</b:key>” +
” <b:value i:nil=\”true\” />” +
” </a:KeyValuePairOfstringanyType>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>ParentLocationId</b:key>” +
” <b:value i:nil=\”true\” />” +
” </a:KeyValuePairOfstringanyType>” +
” </a:Parameters>” +
” <a:RequestId i:nil=\”true\” />” +
” <a:RequestName>CreateFolder</a:RequestName>” +
” </request>” +
“</Execute>” +
“</s:Body>” +

Click here to Download script File, change the extention of the file to js from doc.



Categories: MS CRM 2015

Power shell Cmd to create Forward inbox rule for Email Router – ForwardAsAttachmentTo

Below Power shell cmd will come handy if you want to quickly add forward inbox rule for multiple mailbox in Email Router. If you have 500 mailbox to deploy this rule it will take just 10 seconds to execute compared to 30 minutes in rule deployment wizard

Command :

New-InboxRule -name “ToCRM” -mailbox SourceMailboxEmail -ForwardAsAttachmentTo ForwardmailboxEMail

“ToCRM” – Rule Name just for identification
“SourceMailboxEmail” – Actualmailbox which will forward email as an attachment to the forward mailbox eg:

“ForwardmailboxEMail” – forward mailbox emaill address where all the emails forwarded ef:

You could use Rule deployment wizard but it takes lot of time also if you have more than 25 mailbox and want to deploy rule for selected mailbox it gets to time consuming process.

Categories: MS CRM 2015

Set Unresolved Email in party List using Java Script

While doing google search this morning i found below trick to set unresolved email address on the partylist lookup field

function setUnresolvedRecipient(unresolvedemail) {
        var obj = new Object(); //create the unresolved object = unresolvedemail;
        obj.category = 3; = unresolvedemail;
        obj.type = "9206";
        var toField = Xrm.Page.getAttribute("to");
        var toValue = toField.getValue();
        if (toValue != null) {
            toValue.push(obj); //if there are already other values, add to it
        else {
            toField.setValue([obj]); //if 'to' field is null, just override it
Categories: MS CRM 2015

RetrievePrivilegeForUser failed – no roles are assigned to user

April 24, 2015 1 comment

I had a very interesting issue this morning in one of our on-premise dev environment.  Issue was all of sudden one of our organization not accessible at all , i was able to access other organization on the same server. Same error message was shown to all the user regardless user has admin or ordinary user role.  I stumbled for sometime with this issue then enabled crm trace to capture actual error message. The error message was

“Crm Exception: Message: SecLib::RetrievePrivilegeForUser failed – no roles are assigned to user Returned hr = -2147209463, User: fe0d891a-87ea-e411-80d4-00155d016008, ErrorCode: -2147209463” . I knew I have system administrator role though i just verified this by querying the sql server. Then i queried crm for an user with guid shown in the trace log. Sql returned user name of the Guid that is not at all my user name that’s service account name used in CRM App pool of IIS.

When googled with this error message I found a Microsoft KB article with exact error message

Issue :

By default, when a CRM user is created in Microsoft Dynamics CRM, the user has no security roles. Because the CRM service account is mapped with the newly created user, the CRM service account cannot operate anything. Therefore, the system crashes.

This behavior is by design. Making the account that is running the CRMAppPool into a Microsoft Dynamics CRM user is not supported.


Keep the CRM service account as a dedicated service account.

Kb article explains the issue  but it does not provide resolution to fix the issue.

To fix this issue  i followed below steps

1.Disabled Organization using deployment manager

2.Once disabled, deleted the organization from the deployment Manger

3.Re-imported the organization , while re-importing in user mapping step removed service account user ( CRM App pool)  mapping and and kept all other user mapping as it is.

Once Organization imported everything worked like a charm.

The real story is, one of our new team memebr added service account as a crm user that caused this issue.

Set User Default view using REST API

December 30, 2014 Leave a comment

I had a requirement to update users default view based on their role  programmatically in Bulk  and thought sharing this info that may be helpful for someone

Below script will update users Account entity default view to “Active Accounts”

You need to pass  Entity Typecode,ViewID, Language Code

var entity = {};
entity.PersonalizationSettings = “<DefaultGridViews> <DefaultGridView> <EntityTypeCode>1</EntityTypeCode> <ChildEntityName></ChildEntityName> <QueueId></QueueId> <ViewId>{00000000-0000-0000-00AA-000010001002}</ViewId> <ViewType>1039</ViewType> </DefaultGridView> </DefaultGridViews>”;

var req = new XMLHttpRequest();“POST”, encodeURI(Xrm.Page.context.getClientUrl() + “/XRMServices/2011/OrganizationData.svc/UserSettingsSet(guid’3472C864-F9EC-4FB4-8C35-CFD630ED0696‘)”), true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.setRequestHeader(“X-HTTP-Method”, “MERGE”);
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204 || this.status == 1223) {
alert(“Updated”); //Success – No Return Data – Do Something
else {

Tip : MS CRM 2015 Enable Web resource and Iframe support in Tablet

December 1, 2014 1 comment

MS CRM 2015 looks like going to support  web resources and Iframe in  tablet. Here is the settings where you can configure this.

Go to Settings->Administration->System Settings-> Customization Tab check the “Enable Web resources and Iframes for tablet”

It does says its preview feature only so if you come across any issue, Microsoft may not support.



Categories: MS CRM 2015