How to pass CRM 2011/2013 Custom Lookup attribute extraqs Parameters in openEntityForm utility method from java script

While trying to pass a custom lookup field value as an extraqs parameter,, using the Xrm.Utility.openEntityForm method from my java script, I came across this rule that their is a difference in the way we should set value of a custom lookup and the traditional simple lookup.
with code sample explained below.

var parameters = {};
parameters[“title”] = “Fill in the title here”;
parameters[“customerid”] = custGuid;
parameters[“customeridname”] = custFullName;
parameters[“customeridtype”] = “contact”;
Xrm.Utility.openEntityForm(“incident”, null, parameters);

if you observe above customerid is the actual CRM field schema name of the incident entity. but in the parameters we have passed 2 more additional fields, by suffixing the “customerid” field with “name” for setting the “Name” field of the lookup record and “type” for setting the lookup entity logical name.

while trying the same funda for my custom entity lookup field named “new_customerhometown” , of type “new_hometown” on my incident form open using

parameters[“new_customerhometown”] = homeTownGuid;
parameters[“new_customerhometownname”] = “Hyderbad”;
parameters[“new_customerhometowntype”] = “new_hometown”;

the above code keeps failing with errors. All the web search was taking me to the example of traditional setting of Lookup to Customer or Owner, who use all the below 3 step assignments to perform the task. for example to set the owner field one has to set ownerid, ownername,ownertype=”sustemuser”/”team”

I was going crazy to find the difference between existing lookups like Customer / Owner etc and a custom lookup.
but luckily I found this msdn post, http://msdn.microsoft.com/en-us/library/gg334375.aspx

Capture

so by following the 1st guideline for simple lookup i.e
• 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.Do not use any other arguments.

I set the parameters like below and it worked perfect for me.

parameters[“new_customerhometown”] = homeTownGuid;
parameters[“new_customerhometownname”] = “Hyderbad”;

all I have to do was remove the type assignment. Please note the name parameter is just optional and for setting the Guid field you have to use the attribute schema name as it is. not required to suffix it with any “id” string.

the reason behind such rule to my observation is the traditional look ups like “Owner” / “Customer” / “PartyList” etc can have multiple data types, hence mentioning the type is mandatory else not.

but what I can not understand is, why they need to fail the call, while every other places we use a lookup field we are setting its type why its not allowed here, may be not to increase the url length or whatever, definitely annoyed me a lot 😀

Hope this post helps more !!!

Advertisements
This entry was posted in CRM 2011, CRM 2011 Online, CRM2013, java script, OData and tagged , , , , . Bookmark the permalink.

2 Responses to How to pass CRM 2011/2013 Custom Lookup attribute extraqs Parameters in openEntityForm utility method from java script

  1. CRM.WIZ says:

    It seams that this works when you need to DISAMBIGUATE for fields that accept two types and not needed for fields that only lookup a single type. For example the customerid field on opportunities takes both customers and accounts, this I found needs the parameters[“**********type”] = ******.entityType;

    parentaccount lookup only accounts, hence “parameters[“**********type”]” is not needed.

    var facility = {};
    facility.id = Xrm.Page.getAttribute(“parentaccountid”).getValue()[0].id.replace(/[\])}[{(]/g, ”); //remove (){}[];
    facility.name = Xrm.Page.getAttribute(“parentaccountid”).getValue()[0].name;
    facility.entityType = Xrm.Page.getAttribute(“parentaccountid”).getValue()[0].entityType;
    var parameters = {};
    parameters[“customerid”] = facility.id;
    parameters[“customeridname”] = facility.name;
    parameters[“customeridtype”] = facility.entityType;

    parameters[“parentaccountid”] = facility.id;
    parameters[“parentaccountidname”] = facility.name;

    *Note you do know that you have two “new_” above “new_new_customerhometowntype” that is mostly causing the error.

  2. Isaac Sultan says:

    Thanks for your article. I was also going crazy with the difference between customerid and custom entity lookup that I created. The MSDN published article explains concreately the difference and why in the first you need to pass the typecode and in the second no.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s