Archive

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.

http://develop1.net/public/post/SharePoint-Integration-Reloaded-e28093-Part-3.aspx

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() {
        Xrm.Page.data.entity.addOnSave(function () {
            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();
           xmlhttp.open(“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”, “http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute”);
           xmlhttp.onreadystatechange = function () {
         if (xmlhttp.readyState == 4 && xmlhttp.status != 200) {
                      alert( xmlhttp.responseText);
        }
     };
     xmlhttp.send(buildCreateReq());
     }
}

//Function to build request

function buildCreateReq() {
var recordId = Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”);
return “<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”>” +
” <s:Header>” +
” <SdkClientVersion xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts\”></SdkClientVersion>” +
” </s:Header>” +
” <s:Body>” +
“<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>” +
” <request i:type=\”b:CreateFolderRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\” xmlns:b=\”http://schemas.microsoft.com/crm/2011/Contracts\”>” +
” <a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>FolderName</b:key>” +
” <b:value i:type=\”c:string\” xmlns:c=\”http://www.w3.org/2001/XMLSchema\”>” + Xrm.Page.data.entity.getPrimaryAttributeValue() + “_” + recordId + “</b:value>” +
” </a:KeyValuePairOfstringanyType>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>RegardingObjectType</b:key>” +
” <b:value i:type=\”c:int\” xmlns:c=\”http://www.w3.org/2001/XMLSchema\”>” + Xrm.Page.context.getQueryStringParameters().etc + “</b:value>” +
” </a:KeyValuePairOfstringanyType>” +
” <a:KeyValuePairOfstringanyType>” +
” <b:key>RegardingObjectId</b:key>” +
” <b:value i:type=\”c:string\” xmlns:c=\”http://www.w3.org/2001/XMLSchema\”>” + 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>” +
“</s:Envelope>”;
}

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

createdocumentfolder.doc

 

Advertisements
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: chitra@microsoft.com

“ForwardmailboxEMail” – forward mailbox emaill address where all the emails forwarded ef: emailrouter@microsoft.com

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

http://mscrmbi.blogspot.com/2014/03/set-unresolved-email-ids-in-party-list.html

function setUnresolvedRecipient(unresolvedemail) {
        var obj = new Object(); //create the unresolved object
        obj.name = unresolvedemail;
        obj.category = 3;
        obj.data = 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
            toField.setValue(toValue);
        }
        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

https://support.microsoft.com/en-us/kb/2500917/

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.

Resolution:

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();
req.open(“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 {
alert(this.statusText);
}
}
};
req.send(JSON.stringify(entity));

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.

2014-12-01_1136

 

Categories: MS CRM 2015