Using REST to create CRM record with Lookup Field

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;
Who is Participating?
IT_TechnoConnect With a Mentor Author Commented:
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.
Chinmay PatelEnterprise ArchitectCommented:
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:

IT_TechnoAuthor Commented:
Discovered error myself.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.