How to define workflow conditions? (e.g. activity.state/activity.result)

sougatachakrabo
Kilo Contributor
  • It is quite confusing to me that what is the difference between activity.result == "*something*" and activity.state == "*something*".
  • Where the conditions are defined in servicenow?
  • If I want to define a new condition how can I do it?

Please help me to find out the solution.

6 REPLIES 6

larstange
Mega Sage

Hi



activity.result is normally used to define which output of an activity is used.



activity.state is used to color the activity so you can se if it failed.



If you want to add a new output (condition) of an activity, (this makes most sense in a script activity), you just right click and select "Add condition".



http://wiki.servicenow.com/index.php?title=Condition_Activities#gsc.tab=0


  • Suppose I need a condition named "COMPLETED". This is not the servicenow OOTB conditional feature.
  • Now what shall I do for that?

wf.png


This is a screen shot of my workflow.


  • In the run script I have 3 conditions - -> Waiting , Error , Completed
  • How can I give the conditions of those three in this case.
  • In WAITING state it will fetch the records from REST API. Until it is completed it will go to the timer and again comes back to the RUN SCRIPT.
  • If any error occurred then it will go to another run script.
  • If all data is fetched for the REST API then via completed it goes to LOG MESSAGE.

PLEASE HELP ME OUT.


Hi Sougata,



Double click on the condition and specify the activity.result as in below screenshot:


find_real_file.png


find_real_file.png



Now in the run script you can give your conditions and return the values as below:



find_real_file.png



Let me know if this helps.



Regards,


Prajakta



PS - Hit Like, Helpful or Correct based on the impact of the response.


Hi Prajakta,

I have a similar  kind of requirement, in which i have to use multiple conditions in if loop.
For e.g., their are three conditions in if loop A, B, C(No). and their are resembling checkboxes on the RITM record as well for those conditions. If any of those checkboxes are checked then the workflow should pass through only those conditions resembling the checked fields on the ritm record.


Below is the script i am using: 

 

answer = ifScript();

function ifScript() {
var currentRecord = new GlideRecord('sc_req_item');
currentRecord.addQuery('sys_id', current.sys_id);
currentRecord.query();
gs.info('check here');
if (currentRecord.next()) {
var fieldValue1 = currentRecord.variables.checkbox_field_name1;
var fieldValue2 = currentRecord.variables.checkbox_field_name2;
if (fieldValue1 == true) {
gs.info(' checkbox_fieldname1 condition met');
workflow.scratchpad.branchToTake = "Condition name resembling the checkbox_field_name1";
return 'yes';

}
if (fieldValue2 == true) {
gs.info('checkbox_field_name2 condition met');
workflow.scratchpad.branchToTake = "Condition name resembling the checkbox_field_name2";
return 'yes';

} else {
gs.info('neither of the condition met');
workflow.scratchpad.branchToTake = "No";
return 'No';
}
}
gs.info("Exiting script.");
}

 


also the workflow condition record for both the conditions, do i need to do anything in there? 

Thank you.