cancel
Showing results for 
Search instead for 
Did you mean: 

Autoincrementing project variables dinamically

SOLVED
Occasional Contributor

Autoincrementing project variables dinamically

Hi,

 

I would like to write a function in JS which automatically increments the value of the given project variable as parameter dinamically.

Something like:

function AutoIncrement(variable){
  Project.Variables.$set("VariableByName", variable, ++Project.Variables.$variable);
}

Im not sure how this Project.Variables.$set function works but I guess this is what I need.

I have used it before for setting some bool project variables to false without knowing there exact names.

Obviously it would work only with integers, but that's fine by me.

If possible please give me some examples of the use of $set.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Autoincrementing project variables dinamically

Hi,

 

> Im not sure how this Project.Variables.$set function works

https://support.smartbear.com/testcomplete/docs/reference/language/javascript/set-method.html

 

> If possible please give me some examples

Try this:

function AutoIncrement(variable){
  Project.Variables.$set("VariableByName", variable, Project.Variables.$get("VariableByName", variable) + 1);
}

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
2 REPLIES 2
Community Hero

Re: Autoincrementing project variables dinamically

Hi,

 

> Im not sure how this Project.Variables.$set function works

https://support.smartbear.com/testcomplete/docs/reference/language/javascript/set-method.html

 

> If possible please give me some examples

Try this:

function AutoIncrement(variable){
  Project.Variables.$set("VariableByName", variable, Project.Variables.$get("VariableByName", variable) + 1);
}

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: Autoincrementing project variables dinamically

Thank you, it worked

New Here?
Join us and watch the welcome video: