- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:19 AM
Hi all,
I have the following requirements:
• Once request is submitted approval should go to Manager of the group ‘Food Warriors’.
• Approval Conditions-
o If manager of the group is missing/inactive then request should get closed cancelled.
o If manager of the group rejects the requests then it should be moved to rejected state.
How would I implement this?
For the first task I had initially added an approval - user task to my workflow and added the following script:
answer = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'c9666099973131104a02bcb3f153afb8');
gr.query();
while(gr.next()){
var mng = gr.manager;
}
answer.push('mng');
However, I then realised that I wouldn't be able to implement the last two bullet points. Workflow is the tool that I am struggling the most with on ServiceNow so any help would be greatly appreciated.
Kind regards ,
G
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:36 AM
@gunishi Please refer the below script for IF Activity
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'c9666099973131104a02bcb3f153afb8');
gr.query();
if (gr.next()) {
return 'yes';
}
return 'no';
}
And in your Approval script, I corrected a mistake.
answer = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'c9666099973131104a02bcb3f153afb8');
gr.query();
var mng = '';
if(gr.next()){
var mng = gr.manager;
}
answer.push(mng);
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:45 AM
Before going for approval activity in WorkFlow, please have another IF activity where you check if the Group manager is Missing or Inactive-
in the IF block use this Script
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'c9666099973131104a02bcb3f153afb8');
gr.addQuery('active', 'ture');
gr.query();
if (gr.next()) {
return 'yes';
}
return 'no';
}
IF manager is available link to Approval Activity otherwise set the state to closed complete using set values activity the end the flow.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.👍
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:49 AM
Hi @gunishi ,
Before going for approval activity in WorkFlow, please have another IF activity where you check if the Group has manager or not, IF manager is available link to Approval Activity otherwise set the state to closed complete using set values activity the end the flow.
answer = ifScript();
function ifScript(){
var group = new GlideRecord('sys_user_group');
group.addQuery('sys_id','8a5055c9c61122780043563ef53438e3');
group.query();
if(group.next()){
if(group.manager){
if(group.manager.active == true){
return "yes";
}
return "no";
}
return "no";
}
return "no";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 07:05 AM
Hello @gunishi
Closed Incomplete is not same as closed cancelled.
Please open the "sys_db_object.LIST" then search for the "sc_req_item" in name.
Then in column names search for state and check the choices of that state.
If Closed Incomplete is there then it should have to come if not there then Please add then try to add in workflow.
If this will not work then try to update that using script.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 07:09 AM
Hi @gunishi ,
You can use Run Script Activity
Current.state = "your_state_number"; (Your State Number will be the backend value of Closed Incomplete Choice)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 07:10 AM
Hi @Uday Soni05 and @Harsh_Deep
Thank you both so much for your help today. This has really helped clear some doubts for me.
Kind regards,
G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:45 AM
Before going for approval activity in WorkFlow, please have another IF activity where you check if the Group manager is Missing or Inactive-
in the IF block use this Script
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'c9666099973131104a02bcb3f153afb8');
gr.addQuery('active', 'ture');
gr.query();
if (gr.next()) {
return 'yes';
}
return 'no';
}
IF manager is available link to Approval Activity otherwise set the state to closed complete using set values activity the end the flow.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.👍
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:49 AM
Hi @gunishi ,
Before going for approval activity in WorkFlow, please have another IF activity where you check if the Group has manager or not, IF manager is available link to Approval Activity otherwise set the state to closed complete using set values activity the end the flow.
answer = ifScript();
function ifScript(){
var group = new GlideRecord('sys_user_group');
group.addQuery('sys_id','8a5055c9c61122780043563ef53438e3');
group.query();
if(group.next()){
if(group.manager){
if(group.manager.active == true){
return "yes";
}
return "no";
}
return "no";
}
return "no";
}