Want current table name in a BR ?

Chetan Sondhi
Kilo Sage

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

5 REPLIES 5

salemsap
Tera Expert

Hi,


use the below script to get the table name


current.sys_class_name



Thanks,


Alex


Deepak Ingale1
Mega Sage

use getTableName() method to get table name of current record


Deepak Ingale1
Mega Sage

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()?


Dan_Berglin
Giga Expert

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();