Forum Discussion

michelleunique's avatar
michelleunique
New Contributor
2 years ago
Solved

Using Variables for Numbers that Increase

Hello, 

 

I want to create a test that goes in to our system and tests the function of creating and saving a work order. It needs to open up a new work order and assign that work order a unique number. I believe using a variable in the work order number field is the answer, but a but stumped on how to do it. 

 

Our system won't allow a work order to be saved if it shares the same number as another that is already in the database. So,  I need a way to open a new work order, enter the number of the order created the last time the test ran +1. For instance if I run the test on Monday and it creates Work Order # 151,  when I run the same test on Tuesday, I'd like it to create work order # 152,  and on Wednesday #153, and so on for infinity. 

 

If it's possible to make suggestions keyword-test-style instead of scripting-style, that would be so much appreciated. 

 

Thanks in advance! 

 

  • I believe you could use persistent variables, if you use +1 then the next day it should remember the value and do +1 again and so on...

    They can be found here:

     

    Temporary variables will not be remembered

3 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    As MW_Didata said, persistent variables are the way to go. You might run into an issue if someone else is running the same test from a different TC instance or the work order gets updated some other way outside of TestComplete. If this is an issue, then you can add an If statement to check when you start to make sure that your variable value is greater than the highest one in the database, and if not, display an error.

  • MW_Didata's avatar
    MW_Didata
    Regular Contributor

    I believe you could use persistent variables, if you use +1 then the next day it should remember the value and do +1 again and so on...

    They can be found here:

     

    Temporary variables will not be remembered

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    It can be done, providing you can gain access to the last work order number (is it visible on screen?), for you to increment later. Otherwise, you'll have to query the database to get the last work order number.