- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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');
}
});
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I just noticed the triple =. I've had trouble in some case when checking the typeOf a script variable that was assigned from a client, so I'd go with == and change the logging a bit to provide better feedback, and to make sure there's not a trailing space at the end of the subcategory name:
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('Cat/Subcat: ' + category + ':' + subcategory + ':');
// 1. Logic for Vulnerability Remediation
var vrCategories = [
'vulnerability-UEUDCS',
'vulnerability-UDCSS',
'vulnerability-UISS',
'vulnerability-UDNS',
'vulnerability-Undefined'
];
gs.info('VR subcat: ' + subcategory.toLowerCase() + ':');
for (var i = 0; i < vrCategories.length; i++) {
gs.info('VR Categories: ' + vrCategories[i] + ' :' + vrCategories[i].toString().toLowerCase().indexOf(category.toLowerCase()));
if (vrCategories[i].toString().toLowerCase().indexOf(category.toLowerCase()) >= 0 && subcategory.toLowerCase() == 'vulnerability remediation') {
gs.info('inside if');
assignmentGroupSysId = 'b87934532598ca904db4d91bf5d6c912';
}
}
gs.info('CAT Assignment Group: ' + assignmentGroupSysId);
return assignmentGroupSysId;
},
type: 'VRAssignmentGroupLookup'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Brad,
I inserted the for loop and the vrCategories is still undefined in the logs. Do I need to get the values defined in the client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes, sorry, I just posted your array assignment to the return. Re-post your full script if it's still not working and we'll see what's next.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Brad,
Reposting script include yeah still undefined.
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('Before For LOOP');
gs.info('VR Categories: ' + vrCategories[i].toString().toLowerCase().indexOf(category.toLowerCase()));
gs.info('VR subcat: ' + subcategory.toLowerCase());
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;
},
type: 'VRAssignmentGroupLookup'
