locked
CRM 2013 - Create Record and set "CustomerId" lookup in javascript RRS feed

  • Question

  • Hi,

    I'm trying to create a new record and set the field "customerid" lookup with a value that come from another "customerid"  lookup.

    Here's the code i use :

    var client = Xrm.Page.getAttribute("customerid").getValue();

    var customerObj = new Object(); customerObj.Id = client[0].id; customerObj.Name = client[0].name; var devisObj = new Object(); devisObj.CustomerId = customerObj; var jsonEntity = window.JSON.stringify(devisObj);

    When i execute the create request, i get an error.

    I think this it's because in the customerid lookup, it's possible to choose "Account" or "Contact" and i have to specify the entityType or not ?

    I've tried this 

    var customerObj = new Object();
    customerObj.Id = client[0].id;
    customerObj.Name = client[0].name;

    customerObj.EntityType = client[0].entityType;

    var devisObj = new Object();
    devisObj.CustomerId = customerObj;

    var jsonEntity = window.JSON.stringify(devisObj);

    Without success !

    Someone to help me ? I don't know how i can set customerid in a create request.

    Thank your very much for your help.

    Jean Michel

    Friday, August 1, 2014 2:49 PM

Answers

All replies

  • How about this?

    var entity = {};
    entity.CustomerId = {
        Id: '72CC2308-4B5E-48E0-A9BE-C2E0EE27A701',
        LogicalName: 'account'
    };


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, August 1, 2014 3:13 PM
    Moderator
  • That's perfect !!!

    Thank you soooooo much Jason !

    I'll never forget the param to specify the entity is "LogicalName".

    Thanks again.

    Friday, August 1, 2014 3:43 PM