Update sub grids record in MS CRM

Did you get a requirement to update child entity records available in sub grid in parent entity, so for example if you are working opportunity and you need to update all the related quotes records which is available in quote sub grids under opportunity screen. You can use below code and can modify based on your requirement

function GetAllQuotesIds() {
var gridControl = document.getElementById(“opportunityQuotesGrid”).control; //Change grid name here
var subGrid = gridControl.get_allRecordIds();
for (i = 0; i < subGrid.length; i++) {
var Quote = new Object();
Quote.Name = “Demo”;    // change to update your field
var Id = subGrid[i].replace(“{“, “”).replace(“}”, “”);
UpdateQuotes(Id,Quote); } }

function UpdateQuotes(Id,Quote)
var jsonEntity = JSON.stringify(Quote);
var ODataPath = Xrm.Page.context.getServerUrl() + “/XrmServices/2011/OrganizationData.svc/QuoteSet”; //Change entity name here
$.ajax({ type: “POST”,
contentType: “application/json; charset=utf-8″,
datatype: “json”,
data: jsonEntity,
url: ODataPath + “(guid’” + Id + “‘)”,
beforeSend: function (XMLHttpRequest)
{XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
XMLHttpRequest.setRequestHeader(“X-HTTP-Method”, “MERGE”); },
success: function (data, textStatus, XmlHttpRequest) { alert(“Success”); },
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(“Error while updating record” } }); }

Make sure you have REST and Jquery libraries are added to your form.

Hope it will help someone.

Enjoy !!!

Leave a comment

Filed under Ajax, MS CRM 2011, MS CRM 2013

Quick Tip for “Permission Denied” error in MS CRM

Are you getting “Permission Denied” error and you are confident that all your scripts are working fine and not causing this issue, you may be correct :) it’s not always you will get this error because of your scripts only, you may get this error if you won’t add MS CRM url under trusted sites in your browser, so make sure to ask your clients to add MS CRM url in trusted site before using MS CRM application.

Hope it will help someone.

Enjoy !!!

Leave a comment

Filed under Ajax, MS CRM 2011, MS CRM 2013

Microsoft Dynamics CRM 2013 Online Server IP Address

Recently we did a POC for one of our client and during this POC we demonstrated the integration between MS CRM 2013 online with well-known billing software. The billing software had a prerequisite to store IP address of the servers from where we are consuming their API to communicate with their system. We found this KP where all the MS CRM 2013 online servers IP address are listed based on the region, where your MS CRM 2013 online organization is hosted for example:

North America



Hope it will help someone!!!

Leave a comment

Filed under MS CRM 2013

Disable Notes section in MS CRM 2013 – Quick Tip

Have you been in a situation where you selected ‘Notes’ while creating entity and after that you realize you don’t need to add notes for that entity at all ?? , if yes you know that there is no supported way removing notes once it is added.

So what are all options we have supported or unsupported? If you only want to go with supported way then you need to delete your entity and recreate it. But you are ready to do unsupported changes you have some options to use your existing entity J .

Recently there was a question in MS CRM Development Forum where user was asking for similar question but that was for MS CRM 2011 (For MS CRM 2011 check this) and Jason Lattimer replied with an option to use JQuery for this, so I thought of trying it and sharing it in this post, so that it can help others MS CRM developers as well, if they are looking for a quick fix.

So if you want to disable notes control, you can create a simple JS web-resource and just add a below function in that, you can call this function in entity form onload.

function DisableNotes()

{                $(“#notescontrol a[title='NOTES']“).attr(‘disabled’, ‘disabled’); }

Note: Make sure to add Jquery library to your entity form.

And if you are interested to hide it completely you can use below line

$(“#notescontrol a[title='NOTES']“).css(‘display’, ‘none’);

Of-course if you are interested, you can implement some more business logic to this for example if you want to disable/hide notes control based on user security role then you can write JS to check current user security and use above to after that.

Note: This is a unsupported customization.

Enjoy !!!

Leave a comment

Filed under MS CRM 2013

SnapShot! for Dynamics CRM


Get your organization details, using SnapShot !!!

Originally posted on Microsoft Dynamics CRM links:


System settings and solution components document generator. Creates an Excel file of the CRM organization with a list of all entities, fields, relationships, views, forms, option sets, web resources, Javascript libraries and events, plugins, processes, security roles and many more components.

View original

Leave a comment

Filed under Uncategorized

Step By Step running On-demand workflow for all active records

Did you get a requirement to run your workflow for all active records ? if yes then this post going to help you to implement the same. OOB in MS CRM web client we can run our on-demand workflow only for 250 records, but there are some workaround to overcome this limitation, for example we could use MS CRM Outlook client, because in outlook client there is no limitation for number of records in per page. If you are using outlook client for MS CRM and interested in this workaround check this.
But if you are not use outlook client for MS CRM then you can use Workflow Execution Manager from MSCRM ToolKit. In this post we are going to provide step by step instruction how to use this tool.
So for implementing this requirement we need to follow three steps

  • Create a on- demand workflow for your requirement.
  • Get FetchXML query for your entity records.
  • Configure Workflow Execution Manager to run your workflow.

Create a on- demand workflow
Let’s create our on-demand workflow, in our example we are creating workflow on Account entity to set custom category as standard. So navigate to Settings->Process ->New and fill below details
Process Name:
Entity: Account
Category: Workflow

Click ok and add update step to set account category as “Standard” (click on Set Properties button to set account record category) . Save and Activate our workflow , after completion our workflow should look like below.
Get FetchXML
Now navigate to Advance find and design your query and click on Download Fetch XML to get fetchxml query
advance find
Configure Workflow Execution Manager
Download MS CRM Toolkit from codeplex and extract it. Click on MSCRMToolKit.exe to start and follow below steps.

  • Select Connection Manager and fill below details


  • Test your connection and close connection manager dialog.

Start Workflow Execution Manger from Tool menu and follow below steps
Profile: Provide any name.
Source: Select your connection name.

Click on (Re) Load Workflow button to load your all on-demand workflows.
Paste your query in Records Query text field and Save your profile from File menu.
It should look like below
Click on Execute workflow, it will start your workflow and will process all resultset based on query provided.

1 Comment

Filed under MS CRM 2011

Sending Email with entity attachment from Notes

If you are looking for sending email with an entity record attachment from Notes then this article is going to help you to implement this requirement. We will explain here how to send email using a workflow with an attachment from Notes regarding an entity. Let’s consider a business scenario where we have implemented a customer approval process and as soon as the customer approves we need to send him notification with an attachment in notes, this attachment contains the details about his account.

We can’t access an attachment from Notes in an OOB workflow so we need to write a custom workflow where we need to get an entity record attachment from an annotation entity and need to create an activitymimeattachment record and need to associate it with the email created. While creating the workflow we need to use a create step instead of sending the email so that we can refer to the email record id.

So mainly we need to use the following procedure to implement our requirements:

  • Develop a custom workflow assembly to get an attachment.
  • Create a workflow and use a custom workflow assembly step to send the email.

Let’s create a custom workflow. If you are new to custom workflow assemblies then please refer to our previous article to create a custom workflow. Create a class library project and add the required assemblies to your project. Let’s rename our class file to SendEmailWithAttachement and use the following code:

namespace EmailAttachment


public class SendEmailWithAttachement : CodeActivity


//define output variable



public InArgument<EntityReference> SourceEmail { get; set; }

protected override void Execute(CodeActivityContext executionContext)


// Get workflow context

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

//Create service factory

IOrganizationServiceFactory serviceFactory =          executionContext.GetExtension<IOrganizationServiceFactory>();

// Create Organization service

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

// Get the target entity from the context

Entity  AccountID= (Entity)service.Retrieve(“account”, context.PrimaryEntityId, new ColumnSet(new string[] { “accountid” }));

AddAttachmentToEmailRecord(service, AccountID.Id, SourceEmail.Get<EntityReference>(executionContext));


private void AddAttachmentToEmailRecord(IOrganizationService service, Guid SourceAccountID, EntityReference SourceEmailID)


//create email object

Entity _ResultEntity = service.Retrieve(“email”, SourceEmailID.Id, new ColumnSet(true));

QueryExpression _QueryNotes = new QueryExpression(“annotation”);

_QueryNotes.ColumnSet = new ColumnSet(new string[] { “subject”, “mimetype”, “filename”, “documentbody” });

_QueryNotes.Criteria = new FilterExpression();

_QueryNotes.Criteria.FilterOperator = LogicalOperator.And;

_QueryNotes.Criteria.AddCondition(new ConditionExpression(“objectid”, ConditionOperator.Equal, SourceTrialRequestID));

EntityCollection _MimeCollection = service.RetrieveMultiple(_QueryNotes);

if (_MimeCollection.Entities.Count > 0)

{  //we need to fetch first attachment

Entity _NotesAttachment = _MimeCollection.Entities.First();

//Create email attachment

Entity _EmailAttachment = new Entity(“activitymimeattachment”);

if (_NotesAttachment.Contains(“subject”))

_EmailAttachment["subject"] = _NotesAttachment.GetAttributeValue<string>(“subject”);

_EmailAttachment["objectid"] = new EntityReference(“email”, _ResultEntity.Id);

_EmailAttachment["objecttypecode"] = “email”;

if (_NotesAttachment.Contains(“filename”))

_EmailAttachment["filename"] = _NotesAttachment.GetAttributeValue<string>(“filename”);

if (_NotesAttachment.Contains(“documentbody”))

_EmailAttachment["body"] = _NotesAttachment.GetAttributeValue<string>(“documentbody”);

if (_NotesAttachment.Contains(“mimetype”))

_EmailAttachment["mimetype"] = _NotesAttachment.GetAttributeValue<string>(“mimetype”);



// Sending email

SendEmailRequest SendEmail = new SendEmailRequest();

SendEmail.EmailId = _ResultEntity.Id;

SendEmail.TrackingToken = “”;

SendEmail.IssueSend = true;

SendEmailResponse res = (SendEmailResponse)service.Execute(SendEmail);




Build and register your assembly using plug-in registration tool. Now we need to create our workflow to use our custom assembly step.

Navigate to Settings->Process to create new process. Select Account in entity drop down and workflow in category.

. Now follow below steps to configure workflow

  •  Add condition to check account approval.
  • Add a step to create email record that we can use in custom step
  • Add our custom workflow steps from Add Step.


Click on Set Properties button to set input variable like below

inputvariableAfter completion it should look like below


Save and Activate workflow.

1 Comment

Filed under MS CRM 2011