Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Urgent! How to auto-populate fields in related lists?

Anonym
Kilo Expert

Hey I have a very important problem:

I have a table which was created by extending the task table called x_582999_my_tasks. This table has the fields my_tasks_start and my_tasks_end. 

As well I added the Resource Plan table to the related list of my new table. Now I want to auto-populate the start_date and end_date field of the resource plan, I can create in the related list, with the gives dates of my related task.

How can I do this?

I´m new in Service Now Scripting so it would be very helpful if you may help me with full scripts and the place I need to insert them. 

Thank you so much!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So on the table x_582999_my_tasks you have related list of Resource plan

I assume Resource plan has a reference field to your Custom table (x_582999_my_tasks)

So you can use this logic to set the value on Resource plan based on Start and end

Display Business rule on resource plan table

g_scratchpad.start = current.<field_which_refers_customTable>.my_tasks_start;

g_scratchpad.end = current.<field_which_refers_customTable>.my_tasks_end;

Client Script: on the resource plan table

function onLoad(){

g_form.setValue('start_date', g_scratchpad.start);

g_form.setValue('end_date', g_scratchpad.end);

}

Regards
Ankur

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

View solution in original post

21 REPLIES 21

Hi,

what came in the info message for the dates?

please share that screenshot

Are you using the correct scratchpad variables in client script

Regards
Ankur

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

Hey, I put the screenshot below:

The Scripts are exactly what you sent.

find_real_file.png

Hi,

I could see there is nothing in that scratchpad variable hence it is coming as undefined

so it means

1) you have used incorrect scratchpad variable

OR

2) the dates are empty

please share complete BR and client script here

Regards
Ankur

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

The date fields are filled, so here the other screenshots:

Business rule:

find_real_file.pngfind_real_file.png

And the Client Script:

find_real_file.png