Update the field with sys_id

Chaithu3
Tera Contributor

Hello Experts,

I need to populate a field with the value from another field.

Ex : in description i used to have a value like 

"{'sys_id':'00128698db83d4100a577fa4f3961911','hostname':'test1.com'} "

When the record is getting inserted, then the sys_id value from the above value should insert to another field.

I have written the below code to get the value inserted but still the value comes as empty :

Script 1 :

(function calculatedFieldValue(current) {
var obj = current.description;
gs.info("ID" + obj.sys_id);
if (obj.sys_id) {
return obj.sys_id;
}

}  // Its not working 

 

Script 2 :

// var str = current.description;

// var answer = JSON.stringify(str.sys_id);
// gs.info(answer);
// return answer;

 

find_real_file.png

 

 

Can you please help me with code as earliest.

 

 

Thanks in advance.

 

Looping @Ankur Bawiskar 

 

2 REPLIES 2

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Chaithu,

I think you need to make a before business rule to run on the table on insert, see example below

find_real_file.png

In the script section something like this

find_real_file.png

Hope this helps

 

 

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Chaithu,

Also the object you provided in the string is invalid due to the single quotes, this will cause errors in the script

It should be something like this

'{"sys_id":"00128698db83d4100a577fa4f3961911","hostname":"test1.com"}'