cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1786
Views
10
Helpful
5
Replies

set a task result based on if/else statement

KAKA_2
Level 1
Level 1

based on result of if/else i want to send email (next Task). so assume in a Powershell Task i have sample code as below:

 

$a = 1;

$b = 2;

if ($a -lt $b) {

write-host "Task is successful";

}

else {

write-host "Task failed";

in next Task if it was successful (means entered in if), send email to user and if it failed (means entered in else) send email to admin.

 

Logically script will get executed successfully in any case so it always Trigger the Task (linked with green connector) to send email to user but i want to force it to send email to admin (linked with red connector).

 

i tried Setting ${taskname.POWERSHELL_NATIVE_COMMAND_STATUS} = 0; in else part but this does not help either.

 

any Suggestion?

1 Accepted Solution

Accepted Solutions

Hi Kaka,

 

I mean the standard task "If Else" which you can find in the directory "procedural tasks" in the workflow designer. :)

 

Regards,

Jessi

 

 

View solution in original post

5 Replies 5

jessica.linke
Level 1
Level 1

Hi KAKA_2,

 

is maybe the procendual task "If Else" an option for you?

Normally I'm using this to check a condition ... If the condition true you can using te first connector and send an email to the e.g. user - if the condition false, you can using the second connector to send an email to the administration. And from the email task you can go from the "success" connector to the "failed" task from the workflow to stop them.

 

Or you using a custom task ... I found these example in the UCS Director Cookbook:

Setting a Task to Successful or Failed Status

Objective

Set the Task status to Successful or Failed based on the given condition.

Prerequisites

None

Components

ctxt - Used to set the status message of the workflow task.

Code

if (true) {
	ctxt.setFailed(“Error output message”); // to set the task status as failed 
	ctxt.exit(); // to exit task flow normally
} else {
	ctxt.setSuccessful(); // to set the task status to successful
}

Results

Sets the task status as failed or successful based on the given condition.

Regards,

Jessica

Hello Jessica,

 

What do you mean by "procendual Task"? in this particular case i do not want to use custom Task.

 

Thank You.

-KAKA-

 

Hi Kaka,

 

I mean the standard task "If Else" which you can find in the directory "procedural tasks" in the workflow designer. :)

 

Regards,

Jessi

 

 

Hello Jessi,

 

Thanks. finally i have found it.  with first Impression i see that it look for an condition as Input. in my case, result of Task contains either true or false so i believe i can create a Input variable and set result of prvious Task in this variable which can be later used as test Expression.

 

I will give a try and see if this works.

 

Thanks for your help.

-KAKA-

Hello Jessi,

IFElse Task is doing exactly what i was looking for. Thanks for your help.

-KAKA-

Review Cisco Networking for a $25 gift card

Cisco UCS X-Series Energy Efficiency Offer