Mandatory Attachment Before State Change

amkatulak
Giga Expert

Hi,
I'm wondering if anyone has successfully implemented functionality that would require an attachment before a field on the form can change.   This is not on submission of a catalog item.

Here is our use case:

Legal department puts cases in a 'Pending' state.   In order for them to be removed from pending, the user needs to attach a document.   It can't be just any document attached either, the user would purposefully need to click a button that said something like "Remove from Pending - Doc Attached" or something.

Thanks in advance for any help or advice!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Adam,



Here is the script. Just make sure you add a condition as per your req to trigger it. It will be client script.


Script :


function onSubmit() {


  var att = new GlideRecord("sys_attachment");


  att.addQuery("table_name", "change_request");


  att.addQuery("sys_created_by", g_user.userName);


  att.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');


  att.query();


  if (!att.next()) {


      alert("Please attach the requested form before submitting.");


      return false;


  }


  return true;


}


View solution in original post

13 REPLIES 13

Hi pradeep,



I have a requirement of adding recently uploaded attachment to email notification. Do you have any idea about how to query sys_attachment table to get recent attachment.


pradeepksharma


Hello Pradeep,


I am using your script in Service portal.


Its now working,it not allowing me to submit the form,always populating the message,



Thanks


Saranya


This is a limitation of service-portal.   When you upload an attachment, the attachment is always saved to the sp_portal table with an arbitrary sys_id.   It is not until after the record is submitted and saved that the attachment moves to the correct table with the correct sys_id, so it will be difficult to do validation against.


Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi Pradeep,



this script is gud.


but i want to run this rule for everyone.


not only created by.