NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Set a variable in a post expression

Solved!
Go to solution

I have a loop of tests and if one or more tests fails I want to set a variable "failure" that I can use at the end of the loop for a summary data sheet.

 

In pseudo-code I want:

 

If step.result.status == "Failed"

   then failure = 1

 

There is no else action so the ?: operator doesn't seem appropriate but I see no IF option. So do I need to write something like:

 

(step.result.status == "Failed") ? (locals.failure = 1) : (locals.failure = locals.failure)

 

?

 

thanx,

jvh

0 Kudos
Message 1 of 12
(14,167 Views)

Try the following:

 

Locals.Failure = Step.Result.Status == "Failed" ? 1 : 0

 

I would be careful on using Step.Result.Status as your comparsion as that is not evaluated until the step is completed..  Hence a post expression would not have that evaluated as Failed yet.. Until the Status expression is evaluated.

 

Thanks,

 

PH

 

 

Message 2 of 12
(14,164 Views)

Thanks, didn't know I could use it that way. I was taught (and NI help desk re-iterated that there had to be expressions that include equal signs on both sides of the ":". I don't want to set it to zero if it passes as that would undo other failures, maybe I could do it more C style:

Locals.Failure += Step.Result.Status == "Failed" ? 1 : 0.

 

 

So if "Step.Result.Status" is unsafe what could I use?

 

thanx,

 

jvh

 

0 Kudos
Message 3 of 12
(14,160 Views)

The choices in a conditional operator don't have to be assignments. It may seem a little odd, but you are free to use any expression, such as a constant. Thus:

 

(step.result.status == "Failed") ? (locals.failure = 1) : (locals.failure = locals.failure)

 

could be also:

 

(step.result.status == "Failed") ? (locals.failure = 1) : Nothing

 

or

 

(step.result.status == "Failed") ? (locals.failure = 1) : 0

 

or

 

(step.result.status == "Failed") ? (locals.failure = 1) : ""

 

or

 

(step.result.status == "Failed") ? (locals.failure = 1) : False

Message 4 of 12
(14,157 Views)

I thought I had tried a variant of one of your examples with:

 

(step.result.status == "Failed") ? (locals.failure = 1) : 1. But that is now acceptable, I must have had another mistake.

 

Again, could you suggest something other than using step.result.status since it may not be reliable?

0 Kudos
Message 5 of 12
(14,150 Views)

You could drop in a step afterwards and use PreviousStep.Result.Status.

 

Jim

0 Kudos
Message 6 of 12
(14,146 Views)

If you need an expression evaluated after the status expression, you could put your expression in the Custom Condition of the step's Post Action, with both the true and false outcomes left set to "Goto next step".

0 Kudos
Message 7 of 12
(14,142 Views)

It seemed to work OK as I had it. But since PH said be wary I thought it might be unreliable. 

 

So's I called Austin and they sez post expressions are after the step is complete and it will be OK. We'll see...

 

jvh

0 Kudos
Message 8 of 12
(14,139 Views)

I don't think the person you talked to understood that the expression could depend on the status expression (does your step have a status expression?).

 

Your best bet is to refer to Table 3-4 Order of Actions a Step Performs in the TestStand reference manual.

0 Kudos
Message 9 of 12
(14,131 Views)

Yes, it does have a status expression: 

 

(Step.Result.Status == "Done" && (Step.TS.SData.ThreadOpt == 0 || Step.TS.SData.ThreadOpt == 3)) ? "Passed" : Step.Result.Status

0 Kudos
Message 10 of 12
(14,128 Views)