If activity in workflow

DB1
Tera Contributor

Hi, I have a IF activity that looks like this

DB1_0-1697447582979.png

Script:

workflow.scratchpad.result = ifScript(); 
function ifScript() { 
      var result = {crf_dev_role_auth_caller:false, crf_dev_role_auth_approver:false, crf_dev_role_watchlist:false, none:false};  
      if (JSUtil.notNil(workflow.scratchpad.trigger)) {  
              if (workflow.scratchpad.trigger.indexOf('crf_dev_role_auth_caller') > -1) { 
                      result.crf_dev_role_auth_caller = true;  
              }  
              if (workflow.scratchpad.trigger.indexOf('crf_dev_role_auth_approver') > -1) { 
                      result.crf_dev_role_auth_approver = true;  
              }  
              if (workflow.scratchpad.trigger.indexOf('crf_dev_role_watchlist') > -1) {  
                      result.crf_dev_role_watchlist = true;  
              }  

      }  
          if (!(result.crf_dev_role_auth_caller || result.crf_dev_role_auth_approver || result.crf_dev_role_watchlist)){  
              result.none = true;  
      }  

      //gs.log('---> ' + result.red + ',' + result.blue + ',' + result.green + ',' + result.none,    
      //     'Playing With the If Activity.Validate Trigger');  
      return result;  


}  

Each condition properties looks like: 

workflow.scratchpad.result.crf_dev_role_auth_caller == true

workflow.scratchpad.result.crf_dev_role_auth_approver == true

 

Now I need help to create a run script I think 1 run script to check for the results

for example if(workflow.scratchpad.result.crf_dev_role_auth_caller == true){

// insert a record in Auth caller table

}

if(workflow.scratchpad.result.crf_dev_role_auth_approver == true)

{

//insert record in auth appr table

}

 

I need help with right code to achieve the same as I am unsure if the conditions are correct

 

TIA

@Ankur Bawiskar 

@AnveshKumar M 

@Vishal Birajdar 

@Danish Bhairag2 

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

Hi @DB1 ,

 

You can use "switch activity" instead of if condition & try once. There you wont even need to perform scripting if we need to validate based upon variables present on form.

 

Mark my answer helpful & accepted if helps you answer your question.

 

Thanks,

Danish

Ankur Bawiskar
Tera Patron
Tera Patron

@DB1 

what you wish to do with those variables?

Are those checkboxes in catalog item?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Yes they are checkboxes.

I need to insert records on each different table as mentioned above.

When Auth Caller is checked I need to insert on table 1

Similarly on other tables when other checkbox are selected it has to insert records accordingly