How to set value of a property (which is a chained vocabulary) using DocumentModel.setProperty() API

Hi,

Setting the property value (a chained vocabulary) of a document using DocumentModel.setProperty() does not seem to set the value, when the id provided is that of an entry in the child vocabulary. Could you please provide us some sample/api, to show how to use setProperty() to set the value of a chained vocabulary property.

Eg: Assume that there is a parent vocabulary by name “Country” which is associated with a child vocabulary by name “States”. Now there is a property by name MyCountry which is configured in the respective document type's (say DocumentX) schema. And this “MyCountry” is connected to “Country” vocabulary with the option selected as “Chained vocabulary”. Now let's say that the following are the values of the vocabularies:

Country Vocabulary:

US - Is configured to hold two values “Michigan” and “Chicago” (these values come from child vocabulary “States”) Australia - Is configured to hold two values Melbourne” and “Perth” (these values come from child vocabulary “States”) The ids and labels in the two vocabularies are as follows:

In “Country” vocabulary: Id:1 - Label: US Id:2 -Label: Australia

In “States” vocabulary: Id:3 - Label:Michigan Id:4 - Label:Chicago Id:5 - Label:Melbourne Id:6 - Label:Perth

Now in this example, if DocumentModel.setproperty is invoked with “Id” value as 1, “US” gets set correctly on creation of the DocumentX object If DocumentModel.setproperty is invoked with “Id” value as 2, “Australia” gets set correctly on creation of the DocumentX object If DocumentModel.setproperty is invoked with “Id” value as 3, “3” gets set (instead of “Michigan”) on creation of the DocumentX object If DocumentModel.setproperty is invoked with “Id” value as 4, “4” gets set (instead of “Chicago”) on creation of the DocumentX object If DocumentModel.setproperty is invoked with “Id” value as 5, “5” gets set (instead of “Melbourne”) on creation of the DocumentX object If DocumentModel.setproperty is invoked with “Id” value as 6, “6” gets set (instead of “Perth”) on creation of the DocumentX object

Please let me know if there is any alternate API to set such chained vocabulary values on child vocabularies when creating the document objects

The setProperty() works perfectly for Simple Vocabulary and Hierarchial vocabulary. This problem occurs only if the property is configured on to a Chained vocabulary which has connected Parent and Child vocabularies.

Thank you.

0 votes

1 answers

1610 views

ANSWER



Hi All,

This may help someone:

To set such a value in a vocabulary, the setProperty() method needs to be invoked with the value as “parent-id/child-id”. Eg: For setting the “Michigan” value on the document, one should use the setProperty as setProperty with the value parameter as “1/3”. i.e. documentModel.setProperty(“mySchemaName”,”MyCountry”,”1/3”).

0 votes