Unable to select the items in multiselect through code
回答済みHi,
We have created a template with multiselect control as below:
var templateParams = new BoxMetadataTemplate()
{
TemplateKey = "multiselecttest",
DisplayName = "Multiselect Test",
Scope = "enterprise",
Fields = new List<BoxMetadataTemplateField>()
{
new BoxMetadataTemplateField()
{
Type = "multiSelect",
Key = "author",
DisplayName = "Author",
Options = new List<BoxMetadataTemplateFieldOption>()
{
new BoxMetadataTemplateFieldOption() { Key = "Author1" },
new BoxMetadataTemplateFieldOption() { Key = "Author2" },
new BoxMetadataTemplateFieldOption() { Key = "Author3" },
new BoxMetadataTemplateFieldOption() { Key = "Author4" },
new BoxMetadataTemplateFieldOption() { Key = "Author5" },
new BoxMetadataTemplateFieldOption() { Key = "janani" },
}
}
}
};
BoxMetadataTemplate template1 = await _boxClient.MetadataManager.CreateMetadataTemplate(templateParams);
We applied the above template to a specific file and tried to select few items in the control:
var templateParams = new List<BoxMetadataUpdate>()
{
new BoxMetadataUpdate()
{
Op = MetadataUpdateOp.add,
Path = "/author",
Value = "["Author2","Author3"]"
}
};
Dictionary<string, object> updatedMetadata = await _boxClient.MetadataManager.UpdateFileMetadataAsync(123456, templateParams, "enterprise", "multiselecttest");
We are getting the below error:
The API returned an error [BadRequest | f24yzjgucw9wt1ud.07d752f31b93145c314a9080315bc15f2] schema_validation_failed - instance type (string) does not match any allowed primitive type (allowed: ["array"]) (pointer: /author)
-
正式なコメント
Hi Vijay,
Thank you for bringing this up! I have an answer for you. You will want to create a string array with the options you want.
Hope this helps!
Thanks,
Alex, Box Developer Advocateprivate static async Task CreateMetadataTemplateInstance(BoxClient adminClient)
{
string[] selectedOptions = { "Author1", "Author2"};
var metadataValues = new Dictionary<string, object>()
{
{ "author", selectedOptions }
};
var metadata = await adminClient.MetadataManager.SetFileMetadataAsync(fileId: "123456", metadataValues, "enterprise", "multiselecttest");
Console.WriteLine("Instance Added To File: ", metadata.ToString());
}コメントアクション -
I tried with the below also and getting the same error.
List<string> lstSelectedAuthors = new List<string>() { "Author2", "Author3" };
var metadataValues = new Dictionary<string, object>();metadataValues.Add("author", JsonConvert.SerializeObject(lstSelectedAuthors));
var metadata = await _boxClient.MetadataManager.SetFileMetadataAsync(123456, metadataValues, "enterprise", "multiselecttest");
サインインしてコメントを残してください。
コメント
2件のコメント