Forum Discussion

sanathkd's avatar
sanathkd
Occasional Contributor
4 years ago

Parameterize the context.expand to have dynamic value

Hello all,   I'm trying to parameterize a context.expand and re-use the same method for various properties like below. But the "value" seems not taking properly.  [ Spoiler ] Anyone to guide me ...
  • sanathkd's avatar
    4 years ago

    It is solved now ðŸ˜ƒ I figured it out myself. The script helped me: 

    def propertyStepName = "Properties";

    propertyRead(propertyStepName, "logRef");

    propertyRead(propertyStepName, "user");

     

    public void propertyRead(String propertyStepName, String value){

         def newValue = context.expand('${'+propertyStepName+'#'+value+'}');

    }

     


    sanathkd wrote:

    Hello all,

     

    I'm trying to parameterize a context.expand and re-use the same method for various properties like below.

    But the "value" seems not taking properly. 

    Spoiler
    def logRef = propertyRead (logRef);
    def user = propertyRead (user);
    //-----------------------------------------------------
    public static String propertyRead(String value)
    {
              def newValue = context.expand( '${Properties#{$value}}' );
              return newValue;
    }

    Anyone to guide me here?