- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 07:30 AM
Hello,
I am trying to enforce attachment mandatory based on the variable field value selected on a catalog item. I am using the following script include and catalog client script, unfortunately, I am getting cart id as a "null".
Is there any method to retrieve cart_id, or any corrections to below script is much appreciated.
Script Include:
var getAttachmentAjax = Class.create();
getAttachmentAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAttachment: function() {
var client_table_name = this.getParameter('sysparm_table_name');
var client_sys_id = this.getParameter('sysparm_sys_id');
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addEncodedQuery('table_name=' + client_table_name + '^table_sys_id=' + client_sys_id);
// grAttachment.addQuery("table_name", client_table_name);
// grAttachment.addQuery("table_sys_id", client_sys_id);
grAttachment.query();
if (!grAttachment.next()) {
return 'false';
} else {
return 'true';
}
},
type: 'getAttachmentAjax'
});
On Change client script
var cart_sys_id = '';
if (newValue == 'true') {
var gaAttachmentData = new GlideAjax('global.getAttachmentAjax');
gaAttachmentData.addParam('sysparm_name', 'getAttachment');
gaAttachmentData.addParam('sysparm_sys_id',cart_sys_id);
gaAttachmentData.addParam('sysparm_table_name', 'sc_cart_item');
gaAttachmentData.getXMLAnswer(AttachmentData);
}
}
function AttachmentData(answer) {
// console.log(answer);
if (answer != 'false') {
g_form.setValue('variable_checkbox', true);
g_form.showFieldMsg('variable_checkbox', 'It looks like you attached X attachments.', 'info');
} else {
g_form.setValue('variable_checkbox', false);
g_form.showFieldMsg('variable_checkbox', 'It seems you forgot your attachments.', 'error');
}
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 07:52 AM
Hello vprasad,
Please refer below links,
Hope this will help you to resolve your query.
Kindly mark the answer correct and helpful if it will resolved your query.
Regards,
Akshata
(ServiceNow Developer).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 07:52 AM
Hello vprasad,
Please refer below links,
Hope this will help you to resolve your query.
Kindly mark the answer correct and helpful if it will resolved your query.
Regards,
Akshata
(ServiceNow Developer).