1
votes

I'm using the following ruby gem to connect to the MS Dynamics CRM API: https://github.com/TinderBox/dynamics_crm. I'm having trouble setting the value for any field that is an option set. Using the code below:

client.create('lead', firstname: firstName, lastname: lastName, description: description, emailaddress1: email, subject: topic, 
        companyname: company, telephone1: workPhone, telephone2: homePhone, mobilephone: mobilePhone, description: description, 
        parentcontactid: customer, customerid: customer, parentaccountid: parent, ownerid: team, campaignid: campaign, leadsourcecode: 4)

Everything works fine, except for the leadsourcecode. It returns an error saying incorrect attribute type int. I discovered that there is a virtual attribute called name for option sets, so I tried replaceing leadsourcecode: 4 with leadsourcecodename: "Partner", and it completed without an error, but the value was not set in the CRM. Does anyone have any idea why the value would not be set?

1

1 Answers

1
votes

It's probably because are using the incorrect object type in the attribute. To set an option set in CRM you need to use an OptionSetValue which takes an int in the constructor. Providing a straight int or string won't work.

Not sure about the Ruby equivalent, but in C# this would look like:

Entity e = new Entity("my_entity");
e["my_optionsetfield"] = new OptionSetValue(1);