How do you set a Lookup field?

Jun 19, 2013 at 7:50 PM
Is it possible to set a lookup field with the XrmSvcToolkit? I've done it with the XRM Service toolkit as follows from the documentation:

account.PrimaryContactId = { Id: contactId, LogicalName: "contact" };

I've tried doing the same with XrmSvcToolkit but it fails. Any ideas on getting this working?
Coordinator
Jun 19, 2013 at 8:36 PM
That should work, did you receive any error message?

Thanks,
Daniel
Jun 19, 2013 at 9:14 PM
Hi Daniel, thanks for the reply. I have a lookup on my Account form called new_PersonalContact that I want to include in the create record function to create a new Contact. The Contact form also has the new_PersonalContact lookup field, how can I set this using the code below? I am totally lost on how to do it with your toolkit. Thanks for any help.


XrmSvcToolkit.createRecord({
entityName: "Contact",
entity: {FirstName: "Joe", LastName: "Morris", __New_PersonalContact__:  },
async: false,
successCallback: function (result) {
    var contactId = result.ContactId;

},
errorCallback: function (error) {
    alert("There was an error when creating the contact record");
}
});
Coordinator
Jun 19, 2013 at 10:03 PM
Edited Jun 19, 2013 at 10:05 PM
Have you tried something like this?
XrmSvcToolkit.createRecord({
entityName: "Contact",
entity: {
  FirstName: "Joe", 
  LastName: "Morris", 
  new_PersonalContact: {
    Id: "<THE LONG GUID>",
    LogicalName: "Contact"
  }
},
async: false,
successCallback: function (result) {
    var contactId = result.ContactId;

},
errorCallback: function (error) {
    alert(error);
}
});
It should report the actual error this time, since I have changed the alert. Can you please try that out and let me know? Also, would your look field name be something like new_PersonalContactId?
Jun 22, 2013 at 10:31 AM
Daniel, thank you for reply and fixing the prob; it worked perfectly!! I'm starting to find out that on Load testing this library runs faster than the XRM Service Toolkit. Although I have another question that I have been trying to sort out, but I'll post again so that others benefit.

Thanks for creating the library.