How to set a concept property value dynamically (property name available as string).

How to set a concept property value dynamically (property name available as string).

book

Article ID: KB0085484

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition -
Not Applicable -

Description

Description:
How to set a concept property value dynamically (property name available as string).

Issue/Introduction

How to set a concept property value dynamically (property name available as string).

Resolution

Use the catalog function Instance.Reflection.* to check/set the property value.

Sample RuleFunction:
=====================================================================================
boolean rulefunction RuleFunctions.UpdateCpPropName {
    attribute {
        validity = ACTION;
    }
    scope {
                Concept cp;
                String propName;
                Object propValue;
    }
    body {
   
        boolean bSet=false;
        // get all property Names of the concept
        String [] propArr = Instance.Reflection.getAllPropertyNames(cp);
        for (int i=0;i<propArr@length;i++) {
            if (propArr[i]==propName) {
                Object returnProp = Instance.Reflection.getProperty(cp,propName);
                // update property value
                Instance.Reflection.setPropertyAtomValue(cp,propName,propValue);
                bSet=true;
                break;
            }
        }
           
        if (bSet==false) System.debugOut("### property " + propName + " does not exist for the concept ");
       
        return bSet;
   
    }
}
=====================================================================================