We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to Skip Service Catalog Approval if Manager is opening a Request Item?

Naresh_5120
Tera Contributor

I am working to modify our existing on-boarding Catalog form. Here on our form we have field called "Manager (Employee's direct supervisor).

What I am  looking for  is when a manger himself is opening a request then it should skip the Service Catalog Approval process and create a task , Otherwise if request is opened by someone else it should trigger approval process to manager mentioned in "Manager " field. In order to achieve this i have tried below mention script but somehow it skipping the approval in both scenario, when raised by manager or by others.

answer = ifScript();

 

function ifScript() {

 

var manager = current.variables.nh_manager;

 

var openedBy = current.opened_by;

 

if (manager == openedBy) {

 

return 'yes';

 

} else{

 

return 'no';

 

}

}

 

 On - Boarding form example

find_real_file.png

Variable name of Manager field

find_real_file.png

Can anyone help what I am missing to achieve the desired results. I am new to ServiceNow so my scripting not that advance.

Thanks & Regards,

Naresh 

 

8 REPLIES 8

Brian Bouchard
Mega Sage

Hi Naresh - Try putting some log messaged in your script, then checking System Logs for the output.  You can easily do something like the following to get a better idea of what might be going wrong. in the system Log look for messages starting with TMP to see what you're getting for values in those fields.

 

answer = ifScript();

function ifScript() {
  var manager = current.variables.nh_manager;
  var openedBy = current.opened_by;
  
  gs.log('TMP - MANAGER: ' +manager);
  gs.log('TMP - OPENED BY: ' +openedBy);

  if (manager == openedBy) {
    return 'yes';
  } else{
    return 'no';
  }
}

Hi Brian,

 

Thank you for your quick response.I have tried the suggested steps and found the systems longs as mention below. It looks like does not have any value.

 

find_real_file.png

hi Naresh - It looks like the values are there. They are the sys_ids of the 2 fields.

 

You might try moving your variable declaration before the function

var manager = current.variables.nh_manager;
var openedBy = current.opened_by;

answer = ifScript();

function ifScript() {

  if (manager == openedBy) {
    return 'yes';
  } else{
    return 'no';
  }
}

 

and/or converting the values to a string:

var manager = current.variables.nh_manager.toString();
var openedBy = current.opened_by.toString();

answer = ifScript();

function ifScript() {

  if (manager == openedBy) {
    return 'yes';
  } else{
    return 'no';
  }
}

 

Prateek kumar
Giga Sage

Try this

answer = ifScript();
function ifScript() {
var manager = current.variables.nh_manager.toString();
var openedBy = current.variables.opened_by.toString();
if (manager == openedBy) {
return 'yes';
} else{
return 'no';
}
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks