Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

Adding a predefined value using API


#1

Hi all,

I’m having trouble adding a predefined value to field definition. I use the following code:

  1. first I get the field definition
    fieldDefinition def = Svc.getFieldDefinitions(SessionId, ImagesCatalog, new string[] { fieldName }, true, true)[0];
  2. if the value I’m trying to set is not in def.predefinedValues I call
    Svc.addOrRemovePredefinedValues(SessionId, ImagesCatalog, def, new string[] { value }, null);

I know the issue is not in session id, catalog id or similar - it’s just a matter of calling this method in step 2.
Thanks,
Nejra

P.S. I’ve done more digging - in the list of predefined values there is entry “Bruegel, Pieter the Elder (active 1550/1; died 1569)”. The value for item I’m trying to add is “Bruegel, Pieter the Elder, After (active 1550/1; died 1569)” (so slightly different). When I check def.predefinedValues for my new value clearly it won’t be in there, but when I call the method in step 2 exception I get is "org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint “uc_fdv_field_definition_id_value_order” ". Anybody can point me in the right direction?


#2

Hi Nejra,

It appears you uncovered a bug in addOrRemovePredefinedValues() that prevents adding predefined values to a field definition that already has some predefined values. I have filed a bug and until we can release a fix, a workaround is to use the Asset Service’s setPredefinedValues() method. With that method I was able to add both "Bruegel, Pieter the Elder (active 1550/1; died 1569)” and "Bruegel, Pieter the Elder, After (active 1550/1; died 1569)”. Note that setPredefinedValues() replaces all predefined values on a field definition with the ones you pass.

Please let me know if this solves your issue.

Also, can you tell me what version of Portfolio you are using?

Regards,
Mike


#3

Hi Michael,

thanks for the reply. We use Portfolio 2.0.0 and API 1.0.
Since it’s not a too common requirement, using workaround won’t affect our processing very much, as long as it doesn’t affect the existing data :slight_smile:

Thanks!