How to fetch value from Document ID field

Emeley
Giga Contributor

I am trying to fetch the value of a Document ID field  in after business rule but the script is not able to fetch the value of only Document ID field.

 

var unique = current.getUniqueValue();
var expenses = new GlideRecord('fm_expense_line');
var sc = expenses.get('source_id');

 

I used this script but not able to fetch the values of Source ID field

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

In the example below I'm getting handle to an approval record and using approving field (of type document id) I'm reaching the Change request table and printing the number. the script is tested and works fine

 

var gr = new GlideRecord('sysapproval_approver');
gr.get('007a44badba52200a6a2b31be0b8f525');

var gr1 = new GlideRecord('change_request');
gr1.get(gr.document_id);

gs.print(gr1.number);

 

 

I'm not familiar with the tables you are using but see my comment below

 

var unique = current.getUniqueValue();
var expenses = new GlideRecord('fm_expense_line');
var sc = expenses.get('source_id');   //you are passing source_id as a string (this will never work) while get function can take in sys id only, in strinmg format. Also what is the use of unique there?

 

 

Try below and see if this works for you

 

var sc = '';
var unique = current.getUniqueValue();
var expenses = new GlideRecord('fm_expense_line');
expenses.addQuery('source_id' , unique);
expenses.query();
while(expenses.next())
{
sc = expenses.sys_id;  //use whatever field you want
}
//log ot print result to verify

 

-Anurag

  • Hi @Anurag Tripathi ,
  • I did try executing the same script which you mentioned but it is not working as it is not able to fetch the source_id field.
  • In the example script you have provided you are using get and giving a sys_id there but in my case I am not able to run it using get as I need to compare the field with the sys_id of the current record