- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:01 AM
Hello all,
Once a change request is created on a condition, I want to create 4 Change tasks automatically with unique short description and assign each of them to a different group.
For example,
CTASK1:-
Short description: Enable User in AD
Assignment Group: Active Directory
CTASK2:-
Short description: Provide Asset
Assignment Group: Asset Managenent
CTASK3:-
Short description: ID creation
Assignment Group: Infrastructure department
I have written an after-insert BR, on change request table but it's not working.
Can someone modify my code and help me.
Regards,
Pallavi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:24 AM
Try this
var ar = ['Enable User in AD', 'Provide Asset', 'ID Creation'];
for(var i = 0; i < ar.length; i++) {
gs.log("inside for");
var gr = new GlideRecord('change_task');
gr.initialize();
gr.change_request = current.sys_id;
gr.short_description = ar[i];
gr.u_chgtask_environment = current.u_environment;
gr.cmdb_ci = current.cmdb_ci;
gr.planned_start_date = current.start_date;
gr.planned_end_date = current.end_date;
if(ar[i].toString()=='Enable User in AD ')
gr.assignment_group = 'Active Directory';
else if(ar[i].toString()=='Provide Asset')
gr.assignment_group = 'Asset Management';
else if(ar[i].toString()=='ID creation')
gr.assignment_group = 'Infrastructure department';
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:08 AM
Half of your code is task.XXXX and half is gr.XXX
change task . to gr.
Paste your code as i cannot copy screenshot to modify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:19 AM
Hi Tripathi,
Yeah. you are right. Now I am able to create 3 Ctasks I wanted. But as I mentioned, I am populating array values into every ctask uniquely, but I am not understanding how to populate Assignment groups for those Short description. Can you please help?
Please find my code below.
var ar = ['Enable User in AD', 'Provide Asset', 'ID Creation'];
for(var i = 0; i < ar.length; i++) {
gs.log("inside for");
var gr = new GlideRecord('change_task');
gr.initialize();
gr.change_request = current.sys_id;
gr.short_description = ar[i];
gr.u_chgtask_environment = current.u_environment;
gr.cmdb_ci = current.cmdb_ci;
gr.planned_start_date = current.start_date;
gr.planned_end_date = current.end_date;
gr.insert();
}
Regards,
Pallavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:24 AM
Try this
var ar = ['Enable User in AD', 'Provide Asset', 'ID Creation'];
for(var i = 0; i < ar.length; i++) {
gs.log("inside for");
var gr = new GlideRecord('change_task');
gr.initialize();
gr.change_request = current.sys_id;
gr.short_description = ar[i];
gr.u_chgtask_environment = current.u_environment;
gr.cmdb_ci = current.cmdb_ci;
gr.planned_start_date = current.start_date;
gr.planned_end_date = current.end_date;
if(ar[i].toString()=='Enable User in AD ')
gr.assignment_group = 'Active Directory';
else if(ar[i].toString()=='Provide Asset')
gr.assignment_group = 'Asset Management';
else if(ar[i].toString()=='ID creation')
gr.assignment_group = 'Infrastructure department';
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:37 AM
Thank you Tripathi