Xrm.Utility.openEntityForm setting Look Up field
I am trying to use the Xrm.Utility.openEntityForm () method to open a new custom entity form and set the object's search field programmatically. I am following the example http://msdn.microsoft.com/en-us/library/gg334375.aspx very closely , but I get an indescribable error. Any help with actually setting up the field, or perhaps finding the logs for the error, would be appreciated.
Below is a sample code.
function OpenNewContact() {
var parameters = {};
//Set the Parent Customer field value to "Contoso".
parameters["parentcustomerid"] = "2878282E-94D6-E111-9B1D-00155D9D700B";
parameters["parentcustomeridname"] = "Contoso";
parameters["parentcustomeridtype"] = "account";
//Set the Address Type to "Primary".
parameters["address1_addresstypecode"] = "3";
//Set text in the Description field.
parameters["description"] = "Default values for this record were set programmatically.";
//Set Do not allow E-mails to "Do Not Allow".
parameters["donotemail"] = "1";
// Open the window.
Xrm.Utility.openEntityForm("contact", null, parameters);
}
The function I created to do the same with my custom entity looks like this:
function createNewService() {
var locationId = trimBrackets(Xrm.Page.data.entity.getId());
var primaryField = Xrm.Page.data.entity.getPrimaryAttributeValue();
var entityLogicalName = Xrm.Page.data.entity.getEntityName();
var parameters = {
cw_location: locationId,
cw_locationname: primaryField,
cw_locationtype: entityLogicalName
};
Xrm.Utility.openEntityForm("cw_service", null, parameters);
}
the name of the object from which I open the form job = cw_service (this is not a problem as I can open an empty form with Xrm.Utility.openEntityForm ("cw_service");)
the field name I'm trying to set is cw_location.
I would post an image of the error message, but I don't have a reputation yet.
source to share
For simple searches, you must set the value and text to display in the search. Use the "name" suffix with the attribute name to set a value for the text.
Don't use other arguments for simple searches .
To find customers and owners, you must set the value and name in the same way you set them for a simple search. In addition, you must use the "type" suffix to indicate the type of the object. Valid values ββare account, contact, system administrator, and team.
For your example, this is a simple search, I suppose. So, try using the following code:
var parameters = {
cw_location: locationId,
cw_locationname: primaryField
};
For more information, please visit Specify Search Fields .
source to share