workflow if condition script required

chandra sekhar8
Tera Contributor

I have created workflow as per requirement if after creation of catalog task to fulfillment group Servicenow group up to here is fine.

 

After that I have kept the If condition Please help me how to kept the if condition for this requirement.

catalog task state value:

completed == 15

Cancelled == 77

  Requirement is if catalog task is

completed then request item(ritm)  is set value closed complete 

if catalog task is 

Cancelled the request item (ritm) is set value to closed incomplete

Please find the attachment for your reference to get clear idea about this.

 

main concern is how to write script for if condition for this requirement please help me regarding this.

 

 

2 ACCEPTED SOLUTIONS

nameisnani
Mega Sage

Hi @chandra sekhar8 ,

 

script you can use to write the if condition for your requirement:

 

 

function if_condition(catalog_task_state) {
  if (catalog_task_state == 15) {
    request_item_state = "closed complete";
  } else if (catalog_task_state == 77) {
    request_item_state = "closed incomplete";
  } else {
    request_item_state = "unknown";
  }
  return request_item_state;
}

 

 This script first checks the value of the catalog_task_state variable. If the value is 15, then the script sets the request_item_state variable to "closed complete". If the value is 77, then the script sets the request_item_state variable to "closed incomplete". Otherwise, the script sets the request_item_state variable to "unknown".

 

To use this script, you would need to call it from your workflow. For example, you could use the following code:

 

 

request_item_state = if_condition(catalog_task_state);

 

 

This code would call the if_condition() function and pass the value of the catalog_task_state variable to it. The if_condition() function would then return the appropriate value for the request_item_state variable.

 

 

View solution in original post

Vishal Birajdar
Giga Sage

Hi @chandra sekhar8 

 

You can just add condition in catalog task activity itself to check the state value shown as below.

 

VishalBirajdar7_0-1691125554248.png

 

 

Step 1 : In catalog task activity , Select "wait for completion" checkbox

VishalBirajdar7_1-1691125640230.png

 

Step 2 : Scroll down in catalog task activity and in Related links select 'Condition'

VishalBirajdar7_2-1691125730079.png

 

Step 3 : Remove the always condition and add below conditions 

VishalBirajdar7_4-1691125822255.png

 

VishalBirajdar7_5-1691125860459.png

 

VishalBirajdar7_6-1691125883820.png

 

The state value taken in my case are OOTB , You can check if this works for your custom values.

or else you need to explicitly write a code to make RITM closed incomplete or complete.

 

 

Thanks 

Vishal B

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

2 REPLIES 2

nameisnani
Mega Sage

Hi @chandra sekhar8 ,

 

script you can use to write the if condition for your requirement:

 

 

function if_condition(catalog_task_state) {
  if (catalog_task_state == 15) {
    request_item_state = "closed complete";
  } else if (catalog_task_state == 77) {
    request_item_state = "closed incomplete";
  } else {
    request_item_state = "unknown";
  }
  return request_item_state;
}

 

 This script first checks the value of the catalog_task_state variable. If the value is 15, then the script sets the request_item_state variable to "closed complete". If the value is 77, then the script sets the request_item_state variable to "closed incomplete". Otherwise, the script sets the request_item_state variable to "unknown".

 

To use this script, you would need to call it from your workflow. For example, you could use the following code:

 

 

request_item_state = if_condition(catalog_task_state);

 

 

This code would call the if_condition() function and pass the value of the catalog_task_state variable to it. The if_condition() function would then return the appropriate value for the request_item_state variable.

 

 

Vishal Birajdar
Giga Sage

Hi @chandra sekhar8 

 

You can just add condition in catalog task activity itself to check the state value shown as below.

 

VishalBirajdar7_0-1691125554248.png

 

 

Step 1 : In catalog task activity , Select "wait for completion" checkbox

VishalBirajdar7_1-1691125640230.png

 

Step 2 : Scroll down in catalog task activity and in Related links select 'Condition'

VishalBirajdar7_2-1691125730079.png

 

Step 3 : Remove the always condition and add below conditions 

VishalBirajdar7_4-1691125822255.png

 

VishalBirajdar7_5-1691125860459.png

 

VishalBirajdar7_6-1691125883820.png

 

The state value taken in my case are OOTB , You can check if this works for your custom values.

or else you need to explicitly write a code to make RITM closed incomplete or complete.

 

 

Thanks 

Vishal B

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates