- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2022 11:03 AM
We have a requirement in which user will fill values in category and subcategory variable present in catalog form.
We will check the value filled by user for category and subcategory with the assignment data lookup table(Note Assignment data lookup table have category, subcategory and group). After checking if any category and subcategory is associated to any assignment group, we have to show it in catalog form and give a warning like 'the category and subcategory is already associated to the group_name'. After that we have to clear the category and subcategory field.
Please let mw know if anyone having any idea on how we can implement this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 07:29 AM
Please try below:
Client Script onChange of Subcategory field:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var category=g_form.getValue('current_category');
var subcategory=g_form.getValue('current_subcategory');
var ga = new GlideAjax('MatchCategorySubcategory');
ga.addParam('sysparm_name','assignmentRuleExistence');
ga.addParam('sysparm_category', category);
ga.addParam('sysparm_subcategory', subcategory);
ga.getXML(matchingAssignRule);
// the callback function for returning the result from the server-side code
function matchingAssignRule(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer) {
alert("the category and subcategory is already associated to the group_name");
g_form.clearValue('current_category');
g_form.clearValue('current_subcategory');
}
}
}
Client Callable Script Include:
var MatchCategorySubcategory= Class.create();
MatchCategorySubcategory.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
assignmentRuleExistence: function() {
var cat= this.getParameter("sysparm_category");
var subCat = this.getParameter("sysparm_subcategory");
var assignRule = new GlideRecord('dl_u_assignment');
assignRule.addQuery('category',cat);
assignRule.addQuery('subcategory',subCat);
assignRule.query();
if(assignRule.next())
{
return true;
}
return false;
},
type: 'MatchCategorySubcategory'
});
NOTE: Catalog variables name may differ based on variable names on your instance and check spelling mistakes if any by mistake.
GlideRecord() is a server side API so we cannot use it on client script.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 06:54 PM
You just need to return group name instead of true in script include.
Now your answer will have group name in client script which you can use to add in your alert message.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023