How to pass a variable in other method from method

Good Day Community

Currently when I’m creating a method I always using the below script to get the id

String CPTCode = WebUI.getAttribute(findTestObject('CPT/Add CPT/txtCPTCode'),'id')
String CPTCodeId = WebUI.executeJavaScript("return document.getElementById('${CPTCode}').value;",null)

Is there a way I can only use this script in all methods?

Example : Like in “clickSaveAddCPTActive” Method the String “CPTCodeId” can be use/pass in “clickSaveAddCPTActiveTerm” method

Thanks in Advance!

I am not sure what you are asking.

You want a parameter to the clickSaveAddCPTActiveTerm method, don’t you?

def clickSaveAddCPTActiveTerm(String cptCodeId) {

Hi Kazurayam Good Day

I have string “CPTCodeId” in “clickSaveAddCPTActive” method
Let say this contains id = 100

The question is how to pass “CPTCodeId” which has value = 100 that is currently “clickSaveAddCPTActive” method TO
“clickSaveAddCPTActiveTerm” method

Still I am not sure what you are wondering.

Why not your clickSaveAddCPTActive() method return a String value, which is the CPTCodeId=100, to the caller. Then the caller passes the returned value of the clickSaveAddCPTActiveTerm.

String cptCodeId =  clickSaveAddCPTActive()

def clickSaveAddCPTActive() {
    String CPTCodeId = '100'
    return CPTCodeId
def clickSaveAddCPTActiveTerm(String cptCodeId) {
    print cptCodeId

This will do! thank you and it is working!