Delete a record in any entity in MS CRM
This article describes how you can delete a record in MS CRM using JavaScript. This function requires the following parameters:
- entityname
- entityid
This function calls CrmService.Delete method. For more information see this MSDN article: http://msdn.microsoft.com/en-us/library/cc677071.aspx.
Copy the code in the OnLoad event and call the function in one of the following manners:
- Onsave event of the form
- Onchange of a field (make sure the code does not trigger twice)
- Via an ISV button. This article explains how to add an ISV button.
- Via a button on the form. This post shows how to add a button to your form.
Create a record for any entity in MS CRM
This article describes how you can create a new record in MS CRM using JavaScript. This function can handle multiple fields and values which you can pass via an array.
This function calls CrmService.Create method. For more information see this MSDN article: http://msdn.microsoft.com/en-us/library/cc677070.aspx.
Copy the code in the OnLoad event and call the function in one of the following manners:
- Onsave event of the form
- Onchange of a field (make sure the code does not trigger twice)
- Via an ISV button. This article explains how to add an ISV button.
- Via a button on the form. This post shows how to add a button to your form.
Please note:
This script calls an additional function (on our blog) to check if an array is passed: gIsArray().
Show number of related activities/history for a record – Part 2
Last year I wrote an article on how to display the number of activities for an entity in the navigation pane. See the original post: Show number of related activities/history for a record.
This function however did not include all the Related “Regarding” Records, just the activities directly related to the current record. In other words, when looking at an account you would miss out on the activities related to it’s contacts or opportunities.
I searched the web but found no solution that would also count the Related “Regarding” Records so I decided to write my own using JavaScript. The function counts both activities (=Open or Scheduled) and history (=Completed or Cancelled) items.
Step-by-Step
- Copy the code in the Onload event
- Determine which Related Regarding Entities to include (optional)
By default the filter Related “Regarding” Records shows activities of the related Opportunities, Quotes, Orders, Invoices and Incidents.
In the code below, locate the line “var arrRelatedEntities = new Array();” and add/remove the entities. - Call the function and use the examples below
The Code Read more
Displaying inactive records in associated view
There are a number of ways to display inactive records in an associated view.
MVP George Doubinski wrote an article about how to solve this by using a plugin.
MVP Ronald Lemmen had a different approach via JavaScript. Here is a copy of that post.
Step by Step
- Export Customizations for the specific entity
- Open the XML file with a text editor
- Look for the section ""
- Look for the saved query with the localized name of the associated view
- In that saved query look for the filter that is specified in the columnset
- Remove the filter
- Save the Customizations file
- Import the Customizations file
- Publish the Customizations
Copy record in MS CRM – Ajax
This article explains how you can copy one or more fields from any entity in MS CRM using (Ajax). The main idea is to build a create XML message, gather the entity values and send them to CrmService.Create web method. The method returns a create result of the newly created entity which is then used to create a valid entity url e.g. edit.aspx?id={cloned entity id}.
This function is a server-side function whereby the new entity record is first created and then displayed on the form. When the user decides to cancel this action the new record needs to be deleted manually !!
If you want to copy fields client-side (via Addressable Forms) you can use gCopyRecord().
For more information on copying a records via Ajax see the original post by Adi Kats: Cloning an Entity Part 3 – using Ajax.
Step-by-Step:
- Copy the script in the Onload event.
- If you don’t want to include the popup message in your solution, then simply set the ajaxCloner.Progress.Visible to false.
- You can copy specific fields via the AddField method inside the script (optional). If no fields are defined, all fields will be copied.
- Create a ISV button that calls this function. For more information on how to create an ISV button see: Create ISV toolbar button on a form.
Copy the code in the Onload event and call the function using the example below:
Determine teams for any user in JavaScript
This function is used to determine if the current user is member of a team in MS CRM (example 1). You can also check multiple teams at once (example 2). By passing a user GUID you can also check any other user in the system (example 3).
The function uses the following parameters:
- teams = one team or array of teams to check
- userid = GUID of a user to check the team against. (Optional). If no userid is passed the function will check for the current user.
Copy the code below in the OnLoad and see the examples below on how to call the function:
Determine security roles for any user in JavaScript
This function is used to determine which security role has been assigned to the current user in MS CRM (example 1). You can also check multiple security roles at once (example 2). By passing a user GUID you can also check any user in the system (example 3).
The function uses the following parameters:
- roles = one role or array of roles to check
- userid = GUID of a user to check the role against. (Optional). If no userid is passed the function will check for the current user.
Copy the code below in the OnLoad and see the examples below on how to call the function:
Update a record in any entity in MS CRM
Always wanted to update a record in MS CRM via JavaScript? This article describes how you can update one or multiple fields/attributes at once.
This function calls CrmService.Update method. For more information see this MSDN article: http://msdn.microsoft.com/en-us/library/cc677074.aspx.
Please note:
This script calls an additional function (on our blog) to check if an array is passed: gIsArray().
Copy the code in the OnLoad event and call the function. See the examples below:
Retrieve multiple fields (from any entity) in MS CRM
This function is used to retrieve multiple attributes via MS CRM Webservices and return an array containing the requested values (Example 1). In addtion, this function can be used to retrieve attributes or records for the current (logged in) user e.g. GUID or fullname (Example 2).
Copy the code below in the OnLoad and see the examples below on how to call the function:
Retrieve any field (from any entity) in MS CRM
This function is used to retrieve one attribute from any entity via MS CRM Webservices and return an array with the requested result. In addtion, this function can be used to retrieve user information for the current (logged in) user e.g. GUID or fullname.
When multiple records are found you can request the value of the attribute (example 1), recordcount (example 2) or the entire recordset (example 3 and 4). All these items are returned in an array whereby:
array [0] = record count
array [1] = array (if multiple records are found it returns the entire recordset)
array [2] = value (NOTE: if multiple records are returned it will return the last !! )
Please note:
This script calls an additional function (on our blog) to build the SOAP message and return the results: gGetResultXML().
Copy the code below in the OnLoad and see the examples below on how to call the function:

