- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 09:46 PM - edited 01-03-2023 02:21 AM
Hi All,
I have a catalog item called "XXX Application Access". And we have a variable on the form of type "List collector" where users will be able to select one/more applications from cmdb_ci application table.
Once the request is submitted, the approval should be triggered from the service offering table.
So, for every CI we have a relationship in the CI relationships table. And here Parent is the CI/Application and the Child is mapped to Service Offerings table. Please find the below screen shot for reference.
So, based on this mapping we need to trigger the approval to the Approval Group from the Offerings table for the selected applications on the catalog form.
For example, a user has selected 6 applications in the catalog form.
4 application are having same approval group and the remaining 2 are having some other approval group in the service Offering table.
In this case, we should trigger only 2 approvals in the request for all 6 applications.
one approval is for the first 4 applications since it is having the same group in the service offering table.
and the second approval is for the remaining 2 applications.
And it should complete all the approvals before creating catalog tasks.
Kindly please help me with this flow.
Appreciate your help.
Thanks & Regards,
Priya.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 09:03 PM
@Joshuu Please try below code. It should work.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 08:35 PM
@Joshuu Remove "Catalog task" activity and add "Run script" activity and add below updated code to "Run script" activity.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:22 AM
@Joshuu Yes it was not added. Use below updated code.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:27 AM
Hi @jaheerhattiwale ,
Yes, I have updated the script as below. It is working as expected.
var groups = [];
var appObject = {};
var applications = (current.variables.application_access.toString()).split(",");
for (var i = 0; i < applications.length; i++) {
var cirel = new GlideRecord('cmdb_rel_ci');
cirel.addQuery('parent', applications[i]);
cirel.addQuery('type=5a17d06787f551100c80ec683cbb355e');
cirel.addQuery("child.sys_class_name=service_offering");
cirel.query();
while (cirel.next()) {
if (groups.indexOf(cirel.child.u_access_group.toString()) < 0) {
groups.push(cirel.child.u_access_group.toString());
}
if(appObject[cirel.child.u_access_group.toString()]){
appObject[cirel.child.u_access_group.toString()].push(cirel.parent.getDisplayValue());
}else{
appObject[cirel.child.u_access_group.toString()] = [];
appObject[cirel.child.u_access_group.toString()].push(cirel.parent.getDisplayValue());
}
}
}
task.assignment_group = groups[0];
task.description = 'Please provide access to the following Applications: ' + appObject[groups[0]].toString();
for(var j=1; j<groups.length; j++){
var scTask = new GlideRecord("sc_task");
scTask.initialize();
scTask.request = task.request.toString();
scTask.request_item = task.request_item.toString();
scTask.assignment_group = groups[j];
scTask.description = 'Please provide access to the following Applications: ' + appObject[groups[j]].toString();
scTask.short_description = 'SAAF Access';
scTask.insert();
}
Thank you very much for all your help on this.
Much Appreciated.
Thanks & Regards,
priya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 04:06 AM
Hi @jaheerhattiwale ,
Did you received the screen shot ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 04:08 AM
@Joshuu Yes. But
Catalog Task activity will create only one task.
Your requirement is to create multiple catalog tasks based on number of applications selected right?
One catalog task for one application?
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 08:03 AM
Hi @Community Alums ,
I have tried below script but it is not working. Could you please check.
var answer = [];
var applicationList = current.variables.application_access.getDisplayValue();
var trainees = applicationList.split(',');
for (var i = 0; i < trainees.length; i++) {
var gr1 = new GlideRecord('sc_item_option_mtom');
gr1.addEncodedQuery('request_item' , current.sys_id);
gr1.query();
gs.log('Item: ' + current.sys_id);
while (gr1.next()) {
var cirel = new GlideRecord('cmdb_rel_ci');
cirel.addQuery('parent', applicationList);
cirel.addEncodedQuery('type=5a17d06787f551100c80ec683cbb355e');
cirel.query();
gs.log('App: ' + applicationList);
while (cirel.next()) {
var gr = new GlideRecord('service_offering');
gr.addQuery('name', cirel.child.name);
gr.query();
gs.log('CI: ' + cirel.child.name);
while (gr.next()) {
answer.push(gr.change_control.toString());
}
}
}
}