Using REST to create CRM record with Lookup Field

Posted on 2012-08-28
Last Modified: 2012-09-04
Hi, I managed to review a few blogs on using REST in Java to create records in CRM 2011. I can create the record and pass text fields along to be created with the new record by assigning values to the Object array, this works fine. Problem I have is that I need to populate a few lookup fields in the new record.

I keep getting an error when I try to create records with the lookup value, my code is below, I am running from a Custom form called "new_job" and I am creating a record called "new_tensiletest". I want the lookup field in "new_tensile" to populate with the "new_job". Examples I have seen all revolve around Account and Contact.

I am not sure I am passing the right parameters with the right names.
    var GUIDvalue =;

    var CRMObject = new Object();
    var SampleJob = new Object();
    var SampleName ="new_name").getValue();

    SampleJob.Id = GUIDvalue;
    SampleJob.LogicalName = "new_job";
    SampleJob.Name = SampleName;

    CRMObject.new_tensileid = SampleJob;
Question by:IT_Techno
    LVL 27

    Expert Comment

    by:Chinmay Patel
    Hi IT_Techno,

    Can you describe the error you are getting?

    Also try using this function to setup a lookup field

    // Set lookup value of a field 
    function SetLookupValue(fieldName, id, name, entityType) { 
        if (fieldName != null) { 
            var lookupValue = new Array(); 
            lookupValue[0] = new Object(); 
            lookupValue[0].id = id; 
            lookupValue[0].name = name; 
            lookupValue[0].entityType = entityType; 

    Open in new window

    I have taken the reference from here:


    Accepted Solution

    Hi Chinmay, thanks for your ref, but is more related to a field that is on the form loaded, I am creating a new record altogether which is not loaded and setting the lookup value of a field in the new record.

    I managed to resolve my issue, it was case sensivity. I was referencing the Field Name and not the Schema Name of the field. I also found an easier way to pass values into the array object.

    CRMObject.new_TensileId = { Id: GUIDvalue, LogicalName: "new_job" };

    If I get the Schema Field name wrong, then it was giving me an error. resolve it, now working. I am obviosly new to this and feeling my way through.

    Author Closing Comment

    Discovered error myself.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now