On submit catalog client script is not in service portal but works backend

Chindam Priyank
Tera Contributor
function onSubmit() {

    var cartid = g_form.getValue('sysparm_item_guid');
    var att = new GlideRecord('sys_attachment');
    att.addQuery('table_name', 'sc_cart_item');
    att.addQuery('table_sys_id', cartid);
    att.query();
    if (!att.next()) {
        alert("Please add at least 1 attachment in order to submit request");
return false;
    } else {
        return true;
    }
}
 
Above script is not working for SP. Even we are attaching the attachment still its throwing error. we "cartid" value is empty when submitting through Service portal.
 
Our requirement is attachment is mandatory. It should throw alert message if catalog item is submitted without attachment .
 
Kindly assit us in correcting above onsubmit catalog client script.
2 REPLIES 2

johnfeist
Mega Sage
Mega Sage

Hi Chindam,

 

First off, what error are you getting?  I'd suggest adding a bunch of g_form.addInfoMessage() statements so that you can see where things are failing.  Beyond that, doing back end lookups should be done via AJAX and not attempting to direct query the back end from the front end.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Lucas S Pereira
Tera Contributor

Servicenow recommends using GlideAjax to handle these calls in the Back-End with an include script