Want current table name in a BR ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2015 05:25 AM
Hi
I have written a BR on sys_attachment table to remove existing attachment with same name and update with the latest one . I need this logic on all SN table's so i am looking to get the table name of the form i am creating attachment for .
Please find the code below :
var gr = new GlideRecord('sys_attachment'); | |
gr.addQuery('table_name', 'LIKE', 'incident'); |
//gr.orderBy('table_sys_id');
gr.orderByDesc('sys_created_on');
gr.query();
var lastID = 'not_a_match';
var lastFile = 'not_a_match';
while (gr.next()) {
var isDuplicate = (lastID == gr.table_sys_id) && (lastFile == gr.file_name);
gs.log('Duplicate is' + isDuplicate ); |
lastID = gr.table_sys_id;
lastFile = gr.file_name;
gs.log('Last Id is' + lastID ); | ||
gs.log('last file name is' + lastFile ); | ||
gs.log('task is ' + gr.table_sys_id + ' ' + gr.table_name + ' ' + gr.file_name + ' ' + gr.sys_created_on + ' ' + isDuplicate);
if (isDuplicate)
gr.deleteRecord();
}
I need the table name of the form (in place of incident as shown above) i am creating attachment for , but using current.getTableName() give me sys_attachment table for which this BR is written .
Thanks for your response in advance
Chetan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2015 05:30 AM
Hi,
use the below script to get the table name
current.sys_class_name
Thanks,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2015 06:06 AM
use getTableName() method to get table name of current record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2015 06:13 AM
what is the output of "gr.table_name" in the log message you are trying? is it the sys_id of the table?
can you try gr.table_name.getDisplayValue()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2015 07:24 AM
Hi,
Wouldnt simply this work for you?
var gr = new GlideRecord('sys_attachment'); | |
gr.addQuery('table_name', current.table_name); gr.addQuery('table_sys_id', current.table_sys_id); |
gr.orderByDesc('sys_created_on');
gr.query();