Set Cascading-Select custom field values using the sdk

Hello! I have a custom field of type cascading select. I know how to set the value of the parent object, but I’m stuck on trying to set the child option because I can’t figure out what custom field id value to use.

See my code below. This works great for getting and setting the parent object. How do I set the child object programmatically? Please help!!! Thanks in advance.


 Collection<CustomField> cfColl = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName(Constants.NAME_FIELD);
            long childfieldID = 0;
       
            if (cfColl != null && !cfColl.isEmpty() && cfColl.size()==1) {
                CustomField cf = cfColl.iterator().next();

                Options parentOptionObj = ComponentAccessor.getOptionsManager().getOptions(cf.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig());

                String childOptionID = "";

                String parentOptionID = "";

                for (int i = 0; i < parentOptionObj.size(); i++) {
                    Option o = parentOptionObj.get(i);

                    if (o.getValue().equalsIgnoreCase(Constants.NAME_DEFAULT)) {
                        parentOptionID = String.valueOf(o.getOptionId());

                        Option childOption = parentOptionObj.getOptionForValue(messageDTO.getCarrier(), o.getOptionId());
     
                        if (childOption != null) {
                            childOptionID = String.valueOf(childOption.getOptionId());
                        }
                        break;
                    }
                }
         
                if (!parentOptionID.isEmpty() && !childOptionID.isEmpty()) {
                    issueParams.addCustomFieldValue(cf.getIdAsLong(), parentOptionID);

                    issueParams.addCustomFieldValue(**????**, childOptionID);
                }
1 Like

BUMP! Please help!

Looking at the JSON data transferred from the browser, it adds a “:1” to the customfield ID to set the child. So assuming that your customfield id is 10302 then you should try:

issueParams.addCustomFieldValue("customfield_10302:1", childOptionID);

Just compute the proper string from customfield ID.

Thanks!!

Yes getting the id as a string and adding “:1” to the end fixed the problem!

issueParams.addCustomFieldValue(cf.getId() + ":1", childOptionID);