redmine-net-api icon indicating copy to clipboard operation
redmine-net-api copied to clipboard

UpdateObject not changing Custom Fields in Version objects

Open Elvaron opened this issue 3 years ago • 2 comments

Sorry if this is duplicate, didn't find a matching existing issue.

Using Redmine.Net.Api version 4.3.0 and Redmine version 4.2.4.stable

I have custom fields for versions. Their values are correctly read through Redmine API. But I can neither update nor replace their values.

RedmineManager.UpdateObject( string, Version? ) executes correctly, it just doesn't apply the changes to those custom fields.

Elvaron avatar Mar 02 '22 10:03 Elvaron

Hi, The only fields that you can update for a version are the following: Name, Status, Sharing, DueDate and Description.

For updating version's custom fields you have to run the following command:

RedmineManager.UpdateObject<IssueCustomField>(<IssueCustomFieldId>, <IssueCustomFieldEntity>);

for every custom field that has been changed.

zapadi avatar Mar 06 '22 12:03 zapadi

Hmm, are you sure? I try the following code and it fails with an Unauthorized Exception from WebClient:

foreach (IssueCustomField? customField in version.CustomFields)
{
    if (customField.Id == releasedVersionId)
    {
        // If list null, create
        customField.Values ??= new List<CustomFieldValue>();
        // If list not empty, clear
        customField.Values.Clear();
        // Add new value
        customField.Values.Add(new CustomFieldValue(versionName));

        // Update object
        manager.UpdateObject<IssueCustomField>(customField.Id.ToString(), customField);
    }
}

Elvaron avatar Mar 07 '22 12:03 Elvaron