2

I have property in users that is a managed metadata / taxonomy field, but I'm unable to set it using code from my SharePoint App/Add-In.

UserProfileService.PropertyData[] props = new UserProfileService.PropertyData[1];
props[0] = new UserProfileService.PropertyData();
props[0].Name = "MyTaxonomyProperty";
props[0].Values = new UserProfileService.ValueData[1];
props[0].Values[0] = new UserProfileService.ValueData();
props[0].Values[0].Value = "[{"Id":"0005d8fa-365f-43f7-8d7e-2ca936fa4a69", "Name":"19 - Tax name 1"},{"Id":"bcf3b8c2-dc21-43e4-96dd-28b2571dd3ca", "Name":"13 - Tax name 2"}]";
props[0].IsValueChanged = true;

UserProfileService.UserProfileService ws = new UserProfileService.UserProfileService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
ws.ModifyUserPropertyByAccountName(uid, props);

When I retrieve the value it is in a JSON format but when I try to set the same value I retrieved from SharePoint I get error saying something similar to (translated from Swedish...):

Server was unable to process request - Invalid term value: Input must exist in the closed termset."

What would be the appropriate format of the input string???

1 Answer 1

2

When you sent time to formulate a question on a forum the you focus a Little extra afterwards, and so a solution materialized in this case!

No GUIDs and no JSON, just a plain array of properties with string values!

UserProfileService.PropertyData[] props = new UserProfileService.PropertyData[1];
props[0] = new UserProfileService.PropertyData();
props[0].Name = "MyTaxonomyProperty";
props[0].Values = new UserProfileService.ValueData[2];
props[0].Values[0] = new UserProfileService.ValueData();
props[0].Values[0].Value = "19 - Tax name 1";
props[0].Values[1] = new UserProfileService.ValueData();
props[0].Values[1].Value = "13 - Tax name 2";
props[0].IsValueChanged = true;

UserProfileService.UserProfileService ws = new UserProfileService.UserProfileService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
ws.ModifyUserPropertyByAccountName(uid, props);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy