- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 09:51 PM
Hello,
It is known that when a group approval record (sysapproval_group) is created, then it automatically creates approver records (sysapproval_approver) for all the members in the assignment group field of this group approval record.
As per our script, when a jira ticket is created with certain conditions, it creates change request in ServiceNow and in this script we have a code to include group approval record. script is :
if (istest) {
var TestApprovalGroupSysId = '2d7ad11987b615103ab364e70cbb3523';
this.createGroupApproval(TestApprovalGroupSysId, SNChangeSysID, undefined, 'requested');
gs.eventQueue("change_request.approver.inserted", snChange);
}
createGroupApproval: function(newApproverGroupSysId, SNChangeSysID, dateTime, approvalState) {
var approval_group = new GlideRecord('sysapproval_group');
approval_group.initialize();
approval_group.approval = approvalState;
approval_group.assignment_group = newApproverGroupSysId;
approval_group.parent = SNChangeSysID;
approval_group.sys_created_by = 'integrationuser';
var createdApprovalGroupSysId = approval_group.insert();
if (dateTime) {
// this is only way to set sys_created_on because it can't be set on insert
approval_group.setValue('sys_created_on', dateTime);
approval_group.update();
}
},
With this, when jira ticket is created with certain conditions, group approval record is getting created but this is not generating individual approver records for the members of the assignment group in group approval. How to correct it? Please help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 12:52 AM
you didn't link both the records
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = approvalState;
approval_gr.approver = newApproverSysId;
approval_gr.sysapproval = SNChangeSysID;
approval_gr.sys_created_by = 'integrationuser';
approval_gr.group = createdApprovalGroupSysId;
var createdApproverSysId = approval_gr.insert();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 11:49 PM
you are creating group approval record using script so you need to create sysapproval_approver records for those group members using script only
I don't think system will do this for you using some OOB logic.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 12:04 AM - edited 11-11-2022 12:04 AM
Hi @Ankur Bawiskar ,
Thanks for replying. I tried adding that as shown but it still created only group and not approvers. Can you please help me correct it.
if (test) {
var testApprovalGroupSysId = '2d7ad11987b615103ab364e70cbb3523';
this.createGroupApproval(testApprovalGroupSysId, SNChangeSysID, undefined, 'requested');
var groupmembers = [];
var grmems = new GlideRecord("sys_user_grmember");
grmems.addQuery('group',testApprovalGroupSysId);
grmems.query();
while(grmems.next()){
groupmembers.push(grmems.user.toString());
}
for(var i=0;i<groupmembers.length;i++){
this.createApproverRecord(groupmembers[i], SNChangeSysID, undefined, 'requested');
gs.eventQueue("change_request.approver.inserted", snChange);
}
}
createApproverRecord: function(newApproverSysId, SNChangeSysID, dateTime, approvalState) {
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = approvalState;
approval_gr.approver = newApproverSysId;
approval_gr.sysapproval = SNChangeSysID;
approval_gr.sys_created_by = 'integrationuser';
var createdApproverSysId = approval_gr.insert();
if (dateTime) {
// this is only way to set sys_created_on because it can't be set on insert
approval_gr.setValue('sys_created_on', dateTime);
approval_gr.update();
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 12:52 AM
you didn't link both the records
var approval_gr = new GlideRecord('sysapproval_approver');
approval_gr.initialize();
approval_gr.state = approvalState;
approval_gr.approver = newApproverSysId;
approval_gr.sysapproval = SNChangeSysID;
approval_gr.sys_created_by = 'integrationuser';
approval_gr.group = createdApprovalGroupSysId;
var createdApproverSysId = approval_gr.insert();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 03:08 AM
Hi Ankur,
Thanks!
I have just noticed that the group record from script also created individual approver records. Earlier the records that were created, were getting deleted by another function (named remove approvers) within the same script include.