Dynamics CRM 2016 - Set custom Customer lookup using form parameters

1.6k Views Asked by At

I have a Customer type field in a form with the schema name: myorg_customer. (Note that this is not an out-of-the-box customer field with schema name customerid that comes with CRM.)

I am opening a new Create form using javascript as follows:

var customer = [
                {
                    id: "571A6CE5-3EBC-4672-A164-D8F9654D4FCF",
                    name: "TestContact"
                }
            ];
parameters['myorg_customer'] = customer[0].id;
parameters['myorg_customername'] = customer[0].name;     
parameters['myorg_customertype'] = "contact" // since my customer is a contact instead of an account.

parent.Xrm.Utility.openEntityForm("myorg_myentity", null, parameters);

But after doing so, the page changes to open the Create form but I get an error message saying "An error has occurred". The log file is as follows:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #89B46272Detail: 
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147220970</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>CallStack</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #89B46272</Message>
  <Timestamp>2017-01-03T13:41:22.8457002Z</Timestamp>
  <InnerFault>
    <ErrorCode>-2147220970</ErrorCode>
    <ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
      <KeyValuePairOfstringanyType>
        <d3p1:key>CallStack</d3p1:key>
        <d3p1:value xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">   at Microsoft.Crm.Application.ParameterFilter.ValidateParameter(HttpRequest request, ArrayList parameterCollection, String key, String value, ParameterSources source, EntityType pageEntityType, FormAdditionalAllowedParameters additionalAllowedParameters)
   at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, Boolean alwaysEnableParameterChecking, FormAdditionalAllowedParameters formAdditionalAllowedParametersTemp)
   at Microsoft.Crm.Application.Controls.AppPage.ValidatePageParameters()
   at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</d3p1:value>
      </KeyValuePairOfstringanyType>
    </ErrorDetails>
    <Message>System.InvalidOperationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #46259303</Message>
    <Timestamp>2017-01-03T13:41:22.8457002Z</Timestamp>
    <InnerFault i:nil="true" />
    <TraceText i:nil="true" />
  </InnerFault>
  <TraceText i:nil="true" />
</OrganizationServiceFault>

The same method works when setting an out-of-the-box customer field on a form by setting the customerid, customeridname, and customeridtype parameters.

Any insights?

Thanks,
Anindit

1

There are 1 best solutions below

1
On

You'll need to add myorg_customer, myorg_customername and myorg_customertype as form parameters. Your error message is Crm's bad way of saying the form parameter isn't allowed...

These are the guidelines from the Documentation:

The following guidelines apply when setting the value of a lookup on a form using a query string argument:

  1. For simple lookups you must set the value and the text to display in the lookup. Use the suffix “name” with the name of the attribute to set the value for the text.

    Don’t use any other arguments.

  2. For customer and owner lookups you must set the value and the name in the same way you set them for simple lookups. In addition you must use the suffix “type” to specify the type of entity. Allowable values are account, contact, systemuser, and team.

  3. You can’t set the values for partylist or regarding lookups.

I'd make sure you are using an actual Customer Field Type, and not just a Contact Reference. I'd also make sure that it isn't a regarding or a partylist. If it is, you will need to define parameter values that don't match what CRM is looking for (add Underscores for example myorg_customer_id, myorg_customer_name and myorg_customer_type) and then write code on the onload to read these parameters and populate the correct field.