4

I am attempting to use the Xrm.Utility.openEntityForm() method to open a new custom entity form and programatically set an entity look up field. I am following an example on http://msdn.microsoft.com/en-us/library/gg334375.aspx very closely but getting nondescript error. Any help with actually setting the field or possibly finding the logs for the error would be appreciated.

The code example I am following.

 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 have created to do the same with my custom entity is as follows :

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 entity I am opening a form work = cw_service (this isn't the problem as I can open a blank form with Xrm.Utility.openEntityForm("cw_service");)

the name of the field I am trying to set is cw_location.

I'd post a picture of the error message but I don't have the reputation yet to do that.

CCMag
  • 43
  • 1
  • 6
  • For testing, try hardcoding the values you use when you set the `cw_service.cw_location` field on the form JS into your parameters. That is, set the lookup field via JS on the `cw_service` form and then copy/paste the working values into your `createNewService` function to see what happens. – Jason Faulkner Jan 01 '15 at 13:54

1 Answers1

3

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 for simple lookups.

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.

For your example, it is a simple lookup, I suppose. So, Please try using the code below:

var parameters = {
    cw_location: locationId,
    cw_locationname: primaryField
};

For more information, Please visit Set the value for lookup fields.

Mani
  • 185
  • 1
  • 2
  • 10