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

Attachment Validation based on extension on Native UI Change request form

Ankita NA
Tera Contributor

Hie All,

Please help me out with below query

have to write a validation for attachment for Change Request form, my requirement is if category is " Software" and Risk is " Very High" then when user tries to save the form, he should get an error as " attachment mandatory."

My code is below:

In below how I can validate if attachment is type .jpeg then only allow.

I have written a Before BR on change request table, on Insert and Update the conditions as If 

1 category is " Software" and Risk is " Very High"

2 Category is " Software" and Risk changes to " Very High"

 

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

if(current.category == "Software" && current.risk == '1'){
    var attachment = new GlideRecord("sys_attachment");
    attachment.addQuery("table_sys_id", current.sys_id);
    attachment.query();
    if(!attachment.hasNext()){
        gs.addErrorMessage("Attachment is mandatory");
        current.setAbortAction(true);
    }

    //}
})(current, previous);

 

Thanks

1 ACCEPTED SOLUTION

Anirudh Pathak
Mega Sage

Hi @Ankita NA ,

Try below code - 

if(current.category == "Software" && current.risk == '1'){
    var attachment = new GlideRecord("sys_attachment");
    attachment.addQuery("table_sys_id", current.sys_id);
    attachment.addQuery('content_type','image/jpeg');
    attachment.query();
    if(!attachment.next()){
        gs.addErrorMessage("Attachment is mandatory");
        current.setAbortAction(true);
    }
}

 

 

 

View solution in original post

1 REPLY 1

Anirudh Pathak
Mega Sage

Hi @Ankita NA ,

Try below code - 

if(current.category == "Software" && current.risk == '1'){
    var attachment = new GlideRecord("sys_attachment");
    attachment.addQuery("table_sys_id", current.sys_id);
    attachment.addQuery('content_type','image/jpeg');
    attachment.query();
    if(!attachment.next()){
        gs.addErrorMessage("Attachment is mandatory");
        current.setAbortAction(true);
    }
}