Ask a Question

Using variables within text

SOLVED
Azeddin_Margani
Contributor

Using variables within text

Hi,

 

Could someone please help - I want to use variables fed from spread sheet within piece of text.

 

The part of text i need to replace as variables is highlighted in red:

.ClickItem ("Product Order: Megarider 4 Weekly (Adult). Card 6432323412399756454", 0);

 

My attempted code:

.ClickItem ("Product Order: "Project.Variables.UserData..Value("ProductName") (Adult). Card "Project.Variables.UserData.Value("ProductName")", 0);

 

Is there something wrong with this code?.

 

Your help is appreciated..

 

Regards,

A.M.

 

 

 

 

A.M.
3 REPLIES 3
shankar_r
Community Hero

Maybe we have to write a function that can differentiate the String and and Project variable.

 

Something like this,

 

Excel cell value = "String1<projectvariablename1>String2<projectvariablename2>"

 

then you can write a function which will get the name of the project and returns the project variable value.

 

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

Here you go, this function will replace the things you want.

Untitled.png


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

HKosova
SmartBear Alumni (Retired)


@Azeddin_Margani wrote:
 My attempted code:

.ClickItem ("Product Order: "Project.Variables.UserData..Value("ProductName") (Adult). Card "Project.Variables.UserData.Value("ProductName")", 0);


That's almost correct. You want to concatenate the strings using +:

.ClickItem("Product Order: "
+ Project.Variables.UserData.Value("ProductName")
 + " (Adult). Card "
+ Project.Variables.UserData.Value("CardNumber"), 0);

Alternatively, you can use aqString.Format to build the string. %s are placeholders that will be replaced with the variable values:

var strItem = aqString.Format(
"Product Order: %s (Adult). Card %s"),
Project.Variables.UserData.Value("ProductName"),
Project.Variables.UserData.Value("CardNumber"));
...ClickItem(strItem);

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: