# Can we use reference param without if condition or switch statements in dynamic param

**URL:** <https://community.jenkins.io/t/can-we-use-reference-param-without-if-condition-or-switch-statements-in-dynamic-param/34866>\
**Category:** Jenkinsfile Runner\
**Created:** [August 7, 2025, 10:34am UTC](https://community.jenkins.io/t/can-we-use-reference-param-without-if-condition-or-switch-statements-in-dynamic-param/34866 "2025-08-07T10:34:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagjenkins](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/nagjenkins/32/16328_2.png) [@nagjenkins](https://community.jenkins.io/u/nagjenkins)\
**Post date:** [August 7, 2025, 10:34am UTC](https://community.jenkins.io/t/can-we-use-reference-param-without-if-condition-or-switch-statements-in-dynamic-param/34866/1 "2025-08-07T10:34:05Z")

</div>

I am using dynamic param “jdk\_version” to load JDK version based on the reference parameter Application version “app\_version”. I am able to load JDK version using switch block in script. To optimize the code, tried to pass app\_version to a common method, but it is not sending the updated app\_version value. Is there any other way to pass app\_version value to common method or remove these many switch conditions? Thank you.

```

[$class: ‘DynamicReferenceParameter’,  
choiceType: ‘ET\_FORMATTED\_HTML’,  
omitValueField: true,  
description: ‘’,  
name: ‘jdk\_version’,  
referencedParameters: ‘app\_version’,  
script: [  
$class: ‘GroovyScript’,  
fallbackScript: [  
classpath: ,  
sandbox: true,  
script: “return[‘none’]”  
],  
script: [  
classpath: ,  
sandbox: true,  
script:  
“”"  
switch(app\_version) {  
case “4.0.0”:  
inputBox = ‘’  
break  
case “4.0.1”:  
inputBox = ‘’  
break  
case “4.0.2”:  
inputBox = ‘’  
break  
default:  
inputBox = ‘’  
break  
}

```auto
return inputBox
    """
  ]
]

```

]

```

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [August 7, 2025, 11:37am UTC](https://community.jenkins.io/t/can-we-use-reference-param-without-if-condition-or-switch-statements-in-dynamic-param/34866/2 "2025-08-07T11:37:39Z")

</div>

What do you mean with common method? It must be a method that is within the `script` string of the parameter. You can’t call methods that are defined in the Jenkinsfile directly.

---

<div class="post-metadata">

**Author:** ![nagjenkins](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/nagjenkins/32/16328_2.png) [@nagjenkins](https://community.jenkins.io/u/nagjenkins)\
**Post date:** [August 8, 2025, 6:56am UTC](https://community.jenkins.io/t/can-we-use-reference-param-without-if-condition-or-switch-statements-in-dynamic-param/34866/3 "2025-08-08T06:56:13Z")

</div>

I am able to call a common method from the script, but, not able to pass ref param ‘app\_version’ to common method. app\_version value always remains the same. I am expecting it’s value to change on the app\_version value change

script: [  
classpath: ,  
sandbox: true,  
script:  
“”"  
${getJdkVersion(‘4.0.0’)}  
”””

def getJdkVersion() {

// common method

}

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [August 8, 2025, 7:56am UTC](https://community.jenkins.io/t/can-we-use-reference-param-without-if-condition-or-switch-statements-in-dynamic-param/34866/4 "2025-08-08T07:56:51Z")

</div>

You should be aware that when you enter the parameters of a job the pipeline is not yet running. So all the active choice parameter has is what is in it’s `script` argument. The method `getJdkVersion` is not known at that point in time.  
Now when the pipeline starts running it will update the parameter definition. As you used double quotes it will evaluate the call to `getJdkVersion` and write the return value of that call into the script.  
So the script is not dynamic. You should see this when you look at the config.xml of the job. It guess in the script block of the parameter you will only see the return value of the method call.
