Retrieve one or more fields using FetchXML

December 17, 2010 by Geron Profet · Leave a Comment 

This function is used to retrieve multiple fields in MS CRM via fetchXml and return an array containing the requested values.

The function requires the following parameters:

  • xml            = fetchXml
  • arrFields   = array of attributes to return

When multiple records are found you can request the value of the attribute (example 1), recordcount (example 2) or the entire recordset (example 3). All these items are returned in an array whereby:

  • array [0] = record count
  • array [1] = array: to retrieve MULTIPLE records and multiple fields. The entire recordset (nodes) and fields (childnodes) are returned.
  • array [2] = values: Use to retrieve ONE record and multiple fields. (NOTE: if multiple records are returned it will return the last !! )

Instructions:

To determine the exact fetchxml and fetchlayout follow this procedure:

  1. Use FetchXMLBuilder ( www,fetchxmlbuilder.codeplex.com) to build your fetchXML , or…
  2. Build query in Advanced Find and follow procedure below to get the fetchXML:
  •  
    • Go to advanced find and press F11 to get the address bar.
    • Create the query and layout
    • In address bar paste this line of code:
      javascript:void( new function(){ prompt("Fetch Parameters:",getFetchParams());function getFetchParams(){ return "FetchXml:\n" + advFind.FetchXml + "\n\n" + "LayoutXml:\n" + advFind.LayoutXml + "\n\n" + "EntityName:\n" + advFind.EntityName + "\n\n" + "DefaultAdvancedFindViewId:\n" + advFind.DefaultAdvancedFindViewId } } )
    • Click Enter, all parameters are now in your clipboard and can be pasted in your code

Copy the code below in the OnLoad and see the examples below on how to call the function:

Read more

Delete a record in any entity in MS CRM

October 7, 2010 by Geron Profet · Leave a Comment 

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.

Read more

Create a record for any entity in MS CRM

October 5, 2010 by Geron Profet · Leave a Comment 

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().

Read more

Copy record in MS CRM – Ajax

June 1, 2010 by Geron Profet · Leave a Comment 

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: 

  1. Copy the script in the Onload event.
  2. If you don’t want to include the popup message in your solution, then simply set the ajaxCloner.Progress.Visible to false.
  3. You can copy specific fields via the AddField method inside the script (optional). If no fields are defined, all fields will be copied.
  4. 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.

image  

Copy the code in the Onload event and call the function using the example below: 

Read more

Update a record in any entity in MS CRM

May 19, 2010 by Geron Profet · Leave a Comment 

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: 

Read more

Retrieve multiple fields (from any entity) in MS CRM

May 18, 2010 by Geron Profet · Leave a Comment 

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: 

Read more

Retrieve any field (from any entity) in MS CRM

May 18, 2010 by Geron Profet · Leave a Comment 

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: 

Read more