Getting a table name from a reference field

NeilH2
Giga Guru

I am writing a bit of script which depending on the circumstances could reference 2 different tables.

to keep it tidy and avoid writing multiple glide records I'd like to grab the table name from a reference field and then use it to point the glide record to the correct table.
Example is below:


//gets the last entry from the work notes journal and copies it to the parent request/request item
if (current.parent.getTableName() == 'sc_req_item'){
var table = 'sc_req_item';}
else{
var table = 'sc_request';
}

var rec = new GlideRecord(table);
rec.addQuery('sys_id', current.parent);
rec.query();
while (rec.next()) {
var wrk = current.work_notes.getJournalEntry(1);
rec.work_notes = wrk;
rec.update();
}

2 REPLIES 2

Mark Stanger
Giga Sage

How about this?

current.parent.getRefRecord().getTableName()


Excellent Thanks Mark

I was just missing that final piece of the puzzle