The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Business Rule to populate field values from another table through reference field.

PB8
Kilo Contributor

Hello Team,

Need a help in creating business rule. I am new to servicenow.kindly help on this script.

We have related incident on problem task form and it is reference field to Incident table.once a user selects Incident,

the start and end times of that particular incident should populate in the respective fields on problem task.

Kindly help

Regards,

Swi

1 ACCEPTED SOLUTION

Can you mark the correct answer and close out this thread?

Thanks

View solution in original post

7 REPLIES 7

Dubz
Mega Sage

Set up a before insert/update business rule on the problem table and trigger it with the incident reference field changes, the code will be simple, something like below, change field names as required:

current.start_time = current.incident.start_time;
current.end_time = current.incident.end_time;

PB8
Kilo Contributor

Hi David,

 

Thankyou for your help.

I tried current.variable name on after update business rule and before update as well. It didnot work.

Actually i am writing script on problem task table.

my question is how to glide related incident (reference to incident table) field value on problem task and then how to get values of actual start and end dates of that particular incident selected by user on the problem task.

kindly help me with sample of entire script

Regards,

swi

PB8
Kilo Contributor

Below is the script i tried for this scenario:

 

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

var rel = new GlideRecord('problem_task');
rel.addQuery('problem_task', current.u_related_incident);

rel.query();

if('current.u_related_incident' != '')
{}

var gt = new GlideRecord('incident');
gt.addQuery('incident', current.u_related_incident);
gt.query();

if('u_related_incidentISNOTEMPTY');
{}

if(gt.next()){}

current.u_incident_start_time = gt.u_related_incident.gt.opened_at;

current.u_incident_end_time = gt.u_related_incident.resolved_at;


gt.update();

You dont have to have this complex,

Make the business rule as before update and add condition related incident is not empty ,like below screenshot (i used configuration item field, as i dont have that field in my PDI)

find_real_file.png

And this is in script