- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 02:47 AM
Hi,
Please guide me how to call a script include from Assignment script
I have created an assignment rule and added a script to call script include
example:
var a = new SetAssignmentGroup().populateAssignmentGroup();
script include :
created a script include to fetch the group from cmdb_rel_group table and set the value in assignment_group in incident
The below script include works when called from client script but i need to call the script include from assignment rule script. please guide me how to do that.
var SetAssignmentGroup = Class.create();
SetAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateAssignmentGroup : function(){
var gr=new GlideRecord('cmdb_rel_group');
gr.addQuery('ci',this.getParameter('sysparm_cmdb_ci'));
gr.query();
if(gr.next())
{
return gr.group;
}
},
type: 'SetAssignmentGroup'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 06:19 AM
Hello @Community Alums
You need to make slight change in your script include as show below and you can call the script include function from Assignment rule script as shown below:
if (current.getValue("cmdb_ci")) {
current.assignment_group = new SetAssignmentGroup()._populateAssignmentGroup(current.getValue("cmdb_ci"));
}
Script Include:
var SetAssignmentGroup = Class.create();
SetAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//THE BELOW FUNCTION IS CLIENT CALLABLE FUNCTION THAT CAN BE CALLED FROM CLIENT SCRIPT
populateAssignmentGroup: function() {
var cmdbRecordGuid = this.getParameter("sysparm_cmdb_ci");
// CALL _populateAssignmentGroup function WHICH CAN BE CALLED FROM SERVER SIDE SCRIPT
var assignmentGroup = this._populateAssignmentGroup(cmdbRecordGuid);
return assignmentGroup;
},
//THE BELOW FUNCTION CAN BE CALLED FROM SERVER SIDE SCRIPT ONLY
_populateAssignmentGroup: function(cmdbRecordGuid) {
var gr = new GlideRecord("cmdb_rel_group");
gr.addQuery("ci", cmdbRecordGuid);
gr.query();
if (gr.next()) {
return gr.getValue("group");
} else {
return "";
}
},
type: 'SetAssignmentGroup'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 06:19 AM
Hello @Community Alums
You need to make slight change in your script include as show below and you can call the script include function from Assignment rule script as shown below:
if (current.getValue("cmdb_ci")) {
current.assignment_group = new SetAssignmentGroup()._populateAssignmentGroup(current.getValue("cmdb_ci"));
}
Script Include:
var SetAssignmentGroup = Class.create();
SetAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//THE BELOW FUNCTION IS CLIENT CALLABLE FUNCTION THAT CAN BE CALLED FROM CLIENT SCRIPT
populateAssignmentGroup: function() {
var cmdbRecordGuid = this.getParameter("sysparm_cmdb_ci");
// CALL _populateAssignmentGroup function WHICH CAN BE CALLED FROM SERVER SIDE SCRIPT
var assignmentGroup = this._populateAssignmentGroup(cmdbRecordGuid);
return assignmentGroup;
},
//THE BELOW FUNCTION CAN BE CALLED FROM SERVER SIDE SCRIPT ONLY
_populateAssignmentGroup: function(cmdbRecordGuid) {
var gr = new GlideRecord("cmdb_rel_group");
gr.addQuery("ci", cmdbRecordGuid);
gr.query();
if (gr.next()) {
return gr.getValue("group");
} else {
return "";
}
},
type: 'SetAssignmentGroup'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 12:36 AM - edited 10-04-2022 12:54 AM
Hi,
Great! It works for me.
Thank you for your response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 02:30 AM - edited 10-10-2022 03:30 AM
Hello @Mahendra RC ,
The given solution works fine when we create / modify incident manually.
additionally, i wanted to create and update an incident from other source. (consider Postman - Rest API - post )
when i try to update the record by passing (cmdb_ci) value it is getting updated in incident configuration item field but the assignment group is not populated as per the script . can you please help here and guide me?
The assignment group also should be updated if Ci field is updated in incident.