Make attachment mandatory based on a variable from Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2020 08:31 PM
Hi everyone! I'm fairly new to ServiceNow. I'm having difficulties in making the attachment mandatory based from the value of a variable in Catalog Item.
What I wanted to achieve is when I select Create a New Service, attachment becomes mandatory.
On the same catalog item, I was able auto populate the fields based on the Service Name selected using script include and GlideAjax. What I wanted to achieve is to make mandatory attachment field on a catalog item to be true when Create a New Service is selected and false when not selected using script include and GlideAjax.
Here's my code using script include and GlideAjax.
Script Include
var getService6 = Class.create();
getService6.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMandatoryDetails: function() {
var service6 = this.getParameter('sysparm_user');
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', service6);
gr.query();
// Query user records
if (gr.next()) {
gr.mandatory_attachment = true;
gr.update();
}
},
type: 'getService6'
});
Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getService6'); // Script Include Name
ga.addParam('sysparm_name', 'getMandatoryDetails'); // Specific Function Name within the Script Include
ga.addParam('sysparm_user', g_form.getValue('select_type_of_request')); // Value of the the field
ga.getXML(setUpdate);
function setUpdate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('mandatory_attachment', answer);
}
}
Any insights will be very helpful in understanding script include and GlideAjax. Thank you!
- Labels:
-
Script Debugger
-
Scripting and Coding