Gemini Community Support Site

This Gemini community support site can be used to find solutions to product issues. You can log in using Open Id, Google Profile and even Facebook. Feel free to ask a question or browse FAQs and documentation. Product tour videos are also available along with how-to videos demonstrating key Gemini capabilities.




Updating Custom Lookup Field DataValue **RESOLVED**

api

Hi,

I am trying to update a custom lookup field but cannot do so.

Is there a property setter or something else that I am missing? Thanks.

public CustomFieldDataEN[] GetCustomFieldData(SPListItem item)
    {
        Dictionary<int, string> dataMappings = GenerateFieldDataMappings(item);
        CustomFieldDataEN[] customDataCollection = new CustomFieldDataEN[dataMappings.Count];
        int counter = 0;

        foreach (KeyValuePair<int, string> entry in dataMappings)
        {
            CustomFieldDataEN customField = new CustomFieldDataEN();
            customField.UserID = 1;
            customField.ProjectID = GetProjectId(item);
            customField.CustomFieldID = entry.Key;
            customField.CustomFieldData = entry.Value;
            customField.State = BaseEN.EntityState.New;

            customDataCollection[counter] = customField;
            counter++;
        }

        return customDataCollection;
    }

yu217171
· 1
yu217171
Replies (6)
helpful
0
not helpful

Which web service are you using to issue the update?


Saar Cohen
· 5000
Saar Cohen
helpful
0
not helpful

Hi Saar,

I am using the IssuesService.CreateIssue() method.


yu217171
· 1
yu217171
helpful
0
not helpful

I presume that the issue is created, but the custom field is not populated, correct?
If so. can you check the valyue of the custom field in the database (gemini_customfieldsdata) table?
Also, check Gemini's System Log


Saar Cohen
· 5000
Saar Cohen
helpful
0
not helpful

Hi Saar,

I see that the value has been populated correctly in the database.

select c.fielddata, d.customfieldname from dbo.geminicustomfielddata c inner join dbo.geminiprojects p on c.projectid = p.projectid inner join dbo.gemini_customfielddefinitions d on d.customfieldid = c.customfieldid where p.projectname = 'Keith''s Test Project' and d.customfieldname = 'Date Sensitivity' and c.issueid = 2962

Result:

fielddata customfieldname Hard Date Date Sensitivity


yu217171
· 1
yu217171
helpful
0
not helpful

The value seems to be the lookup description and not the key, this might be the issue.

Usually, when using lookups you have a key field (int) and a description (string), looks like you are setting the string instead of the int.


Saar Cohen
· 5000
Saar Cohen
helpful
0
not helpful

Hi Saar,

Thanks for pointing me in the right direction. I have managed to get this working. I'm posting the snippet to help anyone else who comes across this issue.

private string GetLookupId(int customFieldId, string lookupText) { string lookupId = string.Empty;

        CustomFieldEN customField = this.IssueServiceManager.CustomFieldsService.GetCustomField(customFieldId);

        var lookUpDataEntity = customField.LookupData.FirstOrDefault(x => x.GenericValue.ToUpper() == lookupText.ToUpper());

        if (lookUpDataEntity != null)
            lookupId = lookUpDataEntity.GenericKey;

        return lookupId;
    }

Edit: To create multiple values, delimit your string (lookupId) with a pipe character.

ie: 1|2|3|4


yu217171
· 1
yu217171