Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Get a table field value into another table field

F_bio Santos
Kilo Sage

Im trying to get the value of a field "status" on the table "task_sla" into a custom field I created in the "task [TASK]" table (the field name in "task" is "u_status"), Im using a BR to do this but Im not really sure how to do it, can anyone help ?

BR:

F_bioSantos_0-1694430085349.png


BR Code:

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord('task');
gr.addQuery('u_status');
gr.query();

gr.u_status = current.u_status;

})(current, previous);

  

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@F_bio Santos 

u_status on task table is of what type?

Out of the box task_sla doesn't have Status field.

Did you change the label of an existing field?

The logic will be something like this

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('task');
	if(gr.get(current.task)){
		gr.u_status = current.statusField; // this is the field on task_sla table
		gr.update();
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Hello @F_bio Santos 

 

use the same code of @Ankur Bawiskar 

 

 

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('task');
	if(gr.get(current.task)){
		gr.u_state = current.u_status; // this is the field on task_sla table
		gr.update();
	}

})(current, previous);

 

, just do the modification which i shared.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

 

View solution in original post

11 REPLIES 11

I have this code that will populate the "status" field on "taks_sla", now I want to get this value and put it on the "status" field I created on the table "task" they are both string.

Code Im using to populate "status" on "task_sla" table:

var x = new GlideRecord('task_sla'); 

x.addEncodedQuery('active=true'); 

x.query(); 

while (x.next()) { 

    var percentage = parseInt(x.business_percentage); 

 
 

    if (percentage > 100) 

        x.u_status = 'overdue'; 

    else if (percentage > 75) 

        x.u_status = 'at_risk'; 

    else if (percentage <= 75) 

        x.u_status = 'on_track'; 

 
 

    x.update(); 

} 

the "status" field is a field that I created. I tried the code u sent but it didnt work 😕

Hello @F_bio Santos 

 

use the same code of @Ankur Bawiskar 

 

 

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('task');
	if(gr.get(current.task)){
		gr.u_state = current.u_status; // this is the field on task_sla table
		gr.update();
	}

})(current, previous);

 

, just do the modification which i shared.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

 

Hi @Samaksh Wani it is stil empty, I didnt refer this but the records that I want the "status" field to be populated are being created in a portal using a record producer (the field is not on the record producer it is only on the table).

F_bioSantos_0-1694433686065.png

 

@Samaksh Wani 

ok both the fields are newly created and both have same name u_status and I assume both will be having same choice values

Update as this

var x = new GlideRecord('task_sla'); 
if(x.get(current.task)){
	var percentage = parseInt(x.business_percentage); 
	if (percentage > 100) 
		x.u_status = 'overdue'; 
	else if (percentage > 75) 
		x.u_status = 'at_risk'; 
	else if (percentage <= 75) 
		x.u_status = 'on_track'; 
	x.update(); 
} 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader