The CreatorCon Call for Content is officially open! Get started here.

client callable script include not working in scoped application.

Ubada Barmawar
Giga Guru

Hi everyone,

 

I'm working on a custom table inside scoped application, and I'm trying to execute an OnSubmit client script  which calls script include (defined in same scope), but so far.. either I got null response or no response at all. below are my scripts which are pretty simple but not behaving as expected. basically Im trying to make attachment mandatory on form.

 

client script:

UbadaBarmawar_0-1712603329419.png

 

script include:

UbadaBarmawar_1-1712603542205.png

 have referred multiple community articles and solved queries, nothing seem to work. "sys_attachment" is made available to all scopes.

 

Regards,

Ubada Barmawar.

 

13 REPLIES 13

BrahmjeetTanwar
Tera Guru

Hi Ubada,

 

As Maroon said, you should call hasAttachments instead of hasAttachment in client script. Along with that, before line number 8 which is gr.query(), I would suggest to use gr.setLimit(1) as it will be better in terms of time complexity as we just need 1 record.


Thanks,
Brahm

it doesnt work even if I correct the spelling. attachments are unique for each record created and can be filtered using record sys_id.

Marco0o1
Tera Sage

Hi @Ubada Barmawar ,

 

Can I recomend just create a business rule instead of client script on the onSubmit page, then its need to look like:

Marco0o1_0-1712682615502.png

 

(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.query();
if(gr.hasNext()){
gs.log("yes"); //navigate to the syslog table to look the message
} else{
gs.log("no");
// you can abort the submit is not have a attachment file
gs.addErrorMessage('Insert attachment file.');
current.setAbortAction(true);
}

})(current, previous);

 

 

 

Hope that help you

I already have tried with business rule, It gives info message as record inserted ...also some unneccessary messages are displayed. client script is what I want anyhow.

Nick Parsons
Mega Sage

Change the following:

  • getXMLWait should be getXMLAnswer if you want to use a callback (see the docs for getXMLWait on how to use that if that's what you want to use instead)
  • As others have pointed out, use hasAttachments not hasAttachment
  • As James pointed out, you'll need to call g_form.submit() with the appropriate action to resubmit the form depending on the response you get back (and will need to return false outside your callback to prevent the form submission originally)