- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2015 02:30 AM
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'
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2015 02:38 AM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2015 02:38 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2015 03:21 AM
Thanks for the help Harish.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2015 03:25 AM
Your welcome Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2015 05:14 AM
Harish, actually I want to update the following code such that iff all the attachments are removed from the record, the field 'Has Attachment' should set to 'False':
updateRecordForAttachment();
function updateRecordForAttachment(){
var gr = new GlideRecord('task');
if(gr.get(current.table_sys_id))
{
gr.work_notes = "Attachment: " + current.file_name + " has been removed.";
gr.update();
}
}
The above mentioned code is in the OOB business rule called "Delete Attachment - Update Record"
-------------------------------------------------
Don't know if we can update the script in the following:
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";
}