DavidRouyer / pipedrive-dotnet

Pipedrive.net is an async .NET Standard client for pipedrive.com
MIT License
38 stars 46 forks source link

Modifying PersonCustomField #67

Open gregarican opened 3 years ago

gregarican commented 3 years ago

So I have a routine in my project that is attempting to modify the value of a specific a PersonCustomField. The value associated with the key I need updating is a string, however. Looking at the available functionality, it appears as if I can only set the value to be a numeric datatype. Unless I'm missing something in my logic. Sample code below.

            var personFields = person.CustomFields;
            var personField = new PersonCustomField();
            personField.Value = Convert.ToInt32(armsId);    // Required, although I need to pass my armsId in a string datatype.
            person.CustomFields[armsIdFieldKey] = personField;

Any suggestions as to how I best handle this? Ultimately it would be best if I could define the datatype when I am initializing the new PersonCustomField. But I didn't see how to do this.

gregarican commented 3 years ago

I think I see now. I need to change my code to this, correct?

var personField = new StringCustomField(armsId); person.CustomFields[armsIdFieldKey] = personField;

DavidRouyer commented 3 years ago

When you want to update a custom field which is a person or an organization, you have to pass the ID when you want to update it. See the example below:

var testDeal = await client.Deal.Get(1);
var personField = testDeal.CustomFields["hashOfMyCustomField"]; // null or PersonCustomField

var dealToUpdate = testDeal.ToUpdate();

dealToUpdate.CustomFields["hashOfMyCustomField"] = new LongCustomField(627);

await client.Deal.Edit(testDeal.Id, dealToUpdate);