How to call a script include from assignment Rules - Script

Community Alums
Not applicable

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'
});

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

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'
});

 

 

View solution in original post

3 REPLIES 3

Mahendra RC
Mega Sage

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'
});

 

 

Community Alums
Not applicable

Hi,

 

Great! It works for me.

Thank you for your response.

 

Community Alums
Not applicable

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.