How to get the service catalog cart sys_id of an attachment

varaprasad123
Kilo Guru

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');

}

1 ACCEPTED SOLUTION

Akshata jamdar
Mega Guru

Hello vprasad,

 

Please refer below links,

https://community.servicenow.com/community?id=community_question&sys_id=46318be5db98dbc01dcaf3231f96...

 

https://docs.servicenow.com/bundle/orlando-application-development/page/script/server-scripting/refe...

 

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).

View solution in original post

1 REPLY 1

Akshata jamdar
Mega Guru

Hello vprasad,

 

Please refer below links,

https://community.servicenow.com/community?id=community_question&sys_id=46318be5db98dbc01dcaf3231f96...

 

https://docs.servicenow.com/bundle/orlando-application-development/page/script/server-scripting/refe...

 

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).