Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Update field based on attachment

kunal16
Tera Expert

I have a field 'Has Attachment'(check box) on task table. I want to set the value on this field based on attachment, i.e., if there is any attachment attached to the form, the field 'Has Attachment' should set to 'true'; or else 'false'

1 ACCEPTED SOLUTION

Harish Murikina
Tera Guru

Write display business rule or write before insert or update business rule on the form






var gr = new GlideRecord('sys_attachment');


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


gr.query();


if(gr.getRowCount() <0)


{


// make check box false


}


else


{


//make check box true


}


View solution in original post

11 REPLIES 11

If you write this code after delete it can work try this once



var att = new GlideRecord('task');


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


att.query();


gs.log('test attachment ' + att.getRowCount());


if(!att.next())


{


  att.u_has_attachment = "false";


att.update();


}


No Harish, it didn't work


Write before delete BR on table sys_attchmnet and let me know



var att = new GlideRecord('sys_attachment');


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


att.query();


gs.log('test attachment ' + att.getRowCount());


if(att.getRowCount()<=1)


{


    att.u_has_attachment = "false"; // Please tell me this variable "u_has_attachment " is available on which table


    att.update();


}


The field 'Has Attachment' is a check box on 'task' table


ok write gliderecord on task table and update it