Incident should submit only attachment is available

kpkumar2k9
Tera Contributor

Could you please help me on below

 

My requirement is incident should not be submitted with out attachment.

 

Below is the onsubmit client script and it is not working. Please have a look on it

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var attachmentField = g_form.getControl('attachment');
var attachment = attachmentField.getAttachmentList();
if (attachment.length == 0) {
g_form.addErrorMessage('Incient should not submit without attachment');
return false;
}

}

4 REPLIES 4

James Chun
Kilo Patron

Hi @kpkumar2k9,

 

Is this for a record producer? If so, there is a 'Mandatory Attachment' field which you can set to true to mandate an attachment.

 

Cheers

No @James Chun -- It is incident table

swathisarang98
Giga Sage
Giga Sage

Hi @kpkumar2k9 ,

 

You can create a Before  insert  business rule

Table: Incident

advanced: checked 

If you need this to trigger based on some condition you can configure that in Filter Condition 

inside script:

 

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

    
    if (current.hasAttachments() != true) {
        gs.addInfoMessage("PLease add an attachment before creating the incident");
        current.setAbortAction(true);

    }

})(current, previous);

 

 

swathisarang98_0-1709339162254.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

Anand Kumar P
Giga Patron
Giga Patron

Hi @kpkumar2k9 ,

Refer below link

 

https://www.servicenow.com/community/itsm-forum/how-to-make-attachment-mandatory-in-incident-form/m-... 

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand