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

Balaji3
Kilo Contributor

where should i give my table name?

i don't have any column or check box for attachment mandatory. I just need to know whether attachment is exist or not when i press the button.

Murthy Ch
Giga Sage

Hi balaji,

Is attachement mandatory for form or catalog item ??

If it is for catalog item you need to write catalog client script (ON submit)

PFB:

function onSubmit()

{

//Type appropriate comment here, and begin script below

var countRequired = 2;

if(window == null)

{

// portal

if(this.document.getElementsByClassName('get-attachment').length != countRequired)

{

alert('You must add 2 attachments before submitting this request.');

return false;

} }

else

{

// native view var length = $j("li.attachment_list_items").find("span").length;

if(length != countRequired)

{ alert('You must add 2 attachments before submitting this request.');

return false;

} } }

Thanks,

Murthy

 

Thanks,
Murthy

Thanks Mutrhy for quick reply.....! but i need for form not for catalog item.

if not possible with UI Policy pls let me know by which component code i can achieve this?find_real_file.pngIn the above screen when i click on save it should check attachment is attached or not if not it should throw and error message.

HI balaji

It should not be possible to through UI policy..

As per your screen shot if we click on save button we need to make attachment mandatory right??

 If so we need to write UI actions..

Thanks,

Murthy

Thanks,
Murthy

Hi balaji,

please write this on submit client script and let me know if you found any issues..

function onSubmit() {
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,

Murthy

Thanks,
Murthy