Twitter Image

Passing Values to Forms in MSCRM 2011 and 4.0

Written by Stéphane Dorrekens
Tuesday, 03 May 2011 10:03

In CRM 2011, you can include arguments in the extraqs parameter to set field values. The following requirements must be met:

  • You must encode the parameters passed in the extraqs parameter. Use encodeURIComponent to encode the parameters.
  • The names of the query string arguments must match or include the names of attributes for the entity.
  • Lookup fields must use the suffix 'name' with the attribute name to set the text to display.
  • Lookup fields must use the suffix 'type' with the entity name to set the type of record that is displayed in the lookup.
  • The values passed must be valid.
  • The value cannot be a script.
  • For Boolean fields, use either an integer value of 0 or 1, or a text value of true or false to set the value.
  • For DateTime fields, use the text value of the date.

Here's a sample Javascript opening a new account form and defaulting the name to 'My Account'
window.open("/main.aspx?etn=account&pagetype=entityrecord&extraqs=" +encodeURIComponent("name=My Account"), "_blank", "location=no,menubar=no,status=no,toolbar=no", false);

You can find more examples in the CRM 2011 SDK

Note:

Any attempt to pass an invalid parameter or value will result in an error "InvalidOperationException: CRM Parameter Filter - Invalid parameter"
If you have custom parameters (ie: not a standard MSCRM parameter) that you want to include into the form querystring, you can configure the form to accept custom parameters, via the Form properties or directly in the Form generated XML.
You can find a detail procedure in the 'Configure a Form to Accept Custom QueryString Parameters' article of the CRM 2011 SDK.
The Registry change described here below for  MSCRM 4.0, still works in MSCRM2011, but is not a best practise. At best, it could be used temporary after an upgrade from MSCRM 4.0

In CRM 4.0, to pass field values to a form; the following requirements must be met:

  • The names of the query string arguments must match or include the names of attributes for the entity.
  • Lookup and Customer lookup fields should use the suffix 'name' with the attribute name to set the text to display.
  • Customer lookup fields must use the suffix 'type' with the attribute name to set whether the reference is to an account or a contact.
  • The values passed must be valid.
  • The value cannot be a script.
  • For Lookup fields, include an additional parameter to set the name to be displayed in the lookup. The name of this parameter is the attribute name + 'name'. For example, the Parent Account field in the Account form requires a parameter of 'parentaccountidname'.
  • For Customer lookup fields, the type of record must also be set. The name of this parameter is typically the attribute name + 'type'. For Customer lookup fields the value may be either 'account' or 'contact'. For example, the Parent Customer field in the Contact form requires a parameter of 'parentcustomeridtype'.
  • For Boolean fields, use either an integer value of 0 or 1, or a text value of true or false to set the value.
  • For DateTime fields, use the text value of the date.

Here's a sample Javascript opening a new account form and defaulting the name to 'My Account'
window.open("/sfa/accts/edit.aspx?name=My Account", "_blank", "location=no,menubar=no,status=no,toolbar=no", false);

You can find more examples in the CRM 4.0 SDK

Note:

  • This technique works for all entities except Activity entities (for those, see below comment by Andreas Cieslik)
  • Any attempt to pass an invalid parameter or value will result in an error.

In order to allow passing an invalid parameter (ie: a parameter not actually being a field), you have to create a new registry key in HKLM\Software\Microsoft\MSCRM\DisableParameterFilter (DWORD) and set it to 1. Of course, this is only doable on a On Premise or (Virtual) Private Cloud Installation.

Comments  

 
#3 Andreas Cieslik 2012-03-08 12:32
It's not unsupported as this URL is usually used for user defined (custom) entities but also supports built-in entities.
 
 
#2 S.Dorrekens 2012-03-08 10:06
Hi Andreas,
Thanks for the information.
I presume this is unsupported as it's not a SDK described url but there shouldn't be an issue using it.
 
 
#1 Andreas Cieslik 2012-03-06 09:35
You stated that this technique works for all entities but Activity entities.

Luckily I found a workaround for this:
Instead of using the default "/activities/appointment/edit.aspx" URL you must use the URL "/userdefined/edit.aspx?etc=4201".

Now you can set the "etc"-parameter to the correct object type code. (/sdk/list.aspx to find out the right code)

After this you can use the same technique like for Accounts, etc. (e.g. subject="Test") to prefill the new activity.