Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

onsubmit client script for attachments without getelement

Nitya2
Kilo Guru

We are using below catalog client script for  mandatory attachments , but as per best practices servicenow asking us to use without gel function in 5th line (var cat_id = gel('sysparm_item_guid').value;)

kindly help me to change below code  without gel method

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var condtn = g_form.getValue('Server_com_decom');
if(condtn == 'Commission'){
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
}

1 ACCEPTED SOLUTION

Hi 

Give a final try:

function onSubmit() {

var OwnOther = g_form.getValue('Server_com_decom');
if (OwnOther == 'Commission') {
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
          alert("You must add an attachment before submitting this request.");
          return false;
         }
}

}

 

Thanks

Thanks,
Murthy

View solution in original post

9 REPLIES 9

Hi,

Try this:

var OwnOther = g_form.getValue('Server_com_decom');
if (OwnOther == 'Commission') {

var sysid = g_form.getUniqueValue();

  var attach = new GlideRecord('sys_attachment');

  attach.addQuery('table_sys_id',sysid);

  attach.query();

  if(attach.next()){

  alert("You must add attachment before submitting this request.");

return false;

  }

}

Thanks,
Murthy

Its not working , catalog submitting without attachment also

Hi 

Give a final try:

function onSubmit() {

var OwnOther = g_form.getValue('Server_com_decom');
if (OwnOther == 'Commission') {
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
          alert("You must add an attachment before submitting this request.");
          return false;
         }
}

}

 

Thanks

Thanks,
Murthy

Jaspal Singh
Mega Patron
Mega Patron

Hi Nitya,

 

Refer link for a check as it has all possible options.

Sai155
Kilo Contributor

Hi Nitya

 

You can replace the below line

var cat_id = gel('sysparm_item_guid').value;

with

var cat_id = g_form.getValue('sysparm_item_guid');