Highlighted
Trusted Contributor.
Trusted Contributor.
2294 views

How to pass a parameter value to a variable & use it again in the script in TruClient

Hi,

How to pass a parameter value to a variable & use it again in the script in TruClient.

Say i have two randome number paramteres Email1 & Email2. The email I am generating is :
"perf_LC"+TC.getParam("Email1")+"_Builder_"+TC.getParam("Email2")+"@email-qa.livecareer.com"

comes out to be e.g. - perf_LC3584_Builder_605@email-qa.livecareer.com.
I want to pass this outcome into a variable & then use it somewhere else in the same script. 
if Evaluate JS has to be used, what should be the code? Any help would be really appreciated.

Thanks
Nikhil

0 Likes
4 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: How to pass a parameter value to a variable & use it again in the script in TruClient

Hi,

You should use  Evaluate JavaScript step and the code inside it should be as follows

var emailAddress = "perf_LC"+TC.getParam("Email1")+"_Builder_"+TC.getParam("Email2")+"@email-qa.livecareer.com"

Later one when you wish to use emailAddress as an argument you need to make sure the argument field is set to use JavaScript expression.

If you wish to use emailAddress as part of object identification, for example to find a record in a table based on this value, you should add the prefix ArgsContext prior to emailAddress. 

ArgsContext.emailAddress

If you initialize emailAddress in the Init action and you use it in the Actions section (Iteration context) it is advised to save it as a Global variable in order not to lose its' value in case TruClient resets the memory scope when "Simulate New User each Iteration" is turned on. This should be done as follows.

Global.emailAddress = "perf_LC"+TC.getParam("Email1")+"_Builder_"+TC.getParam("Email2")+"@email-qa.livecareer.com"

Regards,
Shlomi

Highlighted
Trusted Contributor.
Trusted Contributor.

Re: How to pass a parameter value to a variable & use it again in the script in TruClient

 Hi Shlomi,

As suggested , I am using an evaluate Javascript under the step where I am typing an email and using the code-

var emailAddress = "perf_LC"+TC.getParam("Email1")+"_Builder_"+TC.getParam("Email2")+"@email-qa.livecareer.com"

Later on , at the step where I need to insert the same, I am using a Type step as "email Address" as JS. Still it is typing as a plain text, not the value. Refer screenshot & suggest.Email.PNG 
Regards,
Nikhil

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: How to pass a parameter value to a variable & use it again in the script in TruClient

Can you put the expression that you assign to the 'var emailAdress' at the place where you now have the expression "emailAddress"?

 

Note that when you create an local variable as 'var emailAdress', it exists only for the live time of the execution of that piece of javascript  (JS).

You like to use a global variable to let a value survive a JS-code block. You need the namespace 'Global.' So another way to solve this is:

Use in your JS block of code: 'var Global.emailAddress = ....'

Use in your email input field the expression 'Global.emailAddress'

Sometimes you see a remark at the bottom of your JS editor like "Use ArgsContext prefix to access TC API or user defined JS variables" If that is the case change your 'Global.emailAddress' into 'ArgsContext.Global.emailAddress'.

(All without quotes I used to above. You use now "emailAddress" with double quotes. This is just a valid JS expression that results in the expected behaviour)

Signature:
Reward community members who take time to respond and help.
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: How to pass a parameter value to a variable & use it again in the script in TruClient

Hi @nikhilmishra_28,

@JHF Remmelzwaal is right. You should use emailAddress without quotes.

Regards,
Shlomi

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.