- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:02 AM
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:
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:45 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:50 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:53 AM
the "status" field is a field that I created. I tried the code u sent but it didnt work 😕
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 05:01 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 05:03 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader