Glide Ajax script to return group to populate Incident based off cat/sub cat

Brett21
Tera Guru

Hi community,

 

Working on this Script Include and Client script that will auto populate the assignment group based off cat/subcat.  However my assignment group isn't being returned.  My log statements show that my category array is return undefined. Is my syntax correct or is there a better way to do this in a Script include?

 

SCRIPT INCLUDE:

 
var VRAssignmentGroupLookup = Class.create();
VRAssignmentGroupLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getAssignmentGroup: function() {
        var category = this.getParameter('sysparm_category');
        var subcategory = this.getParameter('sysparm_subcategory');
        var assignmentGroupSysId = '';

        gs.info('Starting with Array Logic');
		gs.info('Cat/Subcat: ' + category + ':' + subcategory);

        // 1. Logic for Vulnerability Remediation
        var vrCategories = [
            'vulnerability-UEUDCS',
            'vulnerability-UDCSS',
            'vulnerability-UISS',
            'vulnerability-UDNS',
            'vulnerability-Undefined'
        ];

		gs.info('VR Categories: '+ vrCategories.toLowerCase().indexOf(category));
		gs.info('VR subcat: ' + subcategory.toLowerCase());

        if (vrCategories.toLowerCase().indexOf(category) >= 0 && subcategory.toLowerCase() === 'vulnerability remediation' ) {
            assignmentGroupSysId = 'b87934532598ca904db4d91bf5d6c912';
        }
        gs.info('Array Category1: ' + vrCategories);
        gs.info('Incident Category: ' + category);
        gs.info('Array Category2: ' + vrCategories);
        gs.info('CAT Assignment Group: ' + assignmentGroupSysId);


        return assignmentGroupSysId;
    },

    type: 'VRAssignmentGroupLookup'
});

 

CLIENT SCRIPT:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var ga = new GlideAjax('VRAssignmentGroupLookup');
    ga.addParam('sysparm_name', 'getAssignmentGroup');
    ga.addParam('sysparm_category', g_form.getValue('category'));
    ga.addParam('sysparm_subcategory', g_form.getValue('subcategory'));
    ga.getXMLAnswer(function(answer) {
        if (answer) {
            g_form.setValue('assignment_group', answer);
			alert('answer');
        }
    });

}
1 REPLY 1

Brad Bowman
Kilo Patron

Good job with the logging to start.  You are attempting a string method toLowerCase() on an array, which is not a string.  You can either add a .join(',') before the toLowerCase if you just need to test that the category value is in the array, or maintain the array by executing a for loop on it, inside of which you can convert the value of the member to lowercase to compare to the lowercase category. 

var vrCategories = [
            'vulnerability-UEUDCS',
            'vulnerability-UDCSS',
            'vulnerability-UISS',
            'vulnerability-UDNS',
            'vulnerability-Undefined'
        ];

for (var i = 0; i < vrCategories.length; i++) {
    if (vrCategories[i].toString().toLowerCase().indexOf(category.toLowerCase()) >=0 && subcategory.toLowerCase() === 'vulnerability remediation' ) {
        assignmentGroupSysId = 'b87934532598ca904db4d91bf5d6c912';
        }
}
gs.info('Incident Category: ' + category);
gs.info('CAT Assignment Group: ' + assignmentGroupSysId);

return assignmentGroupSysId;