Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Attachment mandatory script in UI policy.

Balaji3
Kilo Contributor

Hi Techies,

I need help on coding part.....

i need script for attachment mandatory through UI Policy for my custom application when user raise a ticket for servicenow Quebec release.

Thanks in advance.....!

Regards,

Balaji

 

29 REPLIES 29

Kajal Goti
Mega Guru

Hi,

 

Please refer below thread, You will get help

 

https://community.servicenow.com/community?id=community_question&sys_id=4f324174db70afc01cd8a345ca96...

 

If my answer solve your query please mark appropriate response as correct so that the thread will appear as resolved for other users who may have a similar query in the future.

 

i Kajal,

Can you pls help me on the below code.

var inc_sys_id = g_form.getUniqueValue();
alert("test-01....." + inc_sys_id);
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "x_inem_rfc_table"); //Table name x_inem_rfc_table
gr.addQuery("table_sys_id", inc_sys_id);
alert("test-02....." + gr);
gr.query();
if (!gr.next()) {
g_form.addErrorMessage('You must add an attachment before submitting this request.');
return false;
}

 

i use this code in client script for Onsubmit but im getting error message "Submit canceled due to a script error - please contact your System Administrator".

 

Regards,

Balaji

Ankur Bawiskar
Tera Patron

@Balaji 

refer my blog below which would work native + portal

enhance it as per your requirement

Verify Mandatory Attachments Count on Catalog Item

please mark blog as helpful and also bookmark if that helps

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I'm working in custom app and extend from task table so i need the attachment script for this either in client script/Business Rule.

 

Regards,

Balaji

Hi,

then you can have before insert/BR for this

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

var rec = new GlideRecord('sys_attachment');

rec.addQuery('table_sys_id', current.sys_id);

rec.query();

if(!rec.next()){

gs.addErrorMessage('Please add attachment');

current.setAbortAction(true);

}

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader