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.

How to fetch value on load while creating new record from parent record

Community Alums
Not applicable

Hi Team,

I have a requirement wherein when we click on New Order task from the related list, it should then fetch some values and  copy it to the fields of the order task.

I am writing the below code in OnLoad client sce

find_real_file.png

 

 

wI am writing the below code in screenshot but alert is throwin blank record instead of sys_id

find_real_file.png

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

I would suggest to use the display business rule to get the parents details and copied to g_scratchpad variables.

for example:

        g_scratchpad.parent_number = current.parent.number;

 

You can use these g_scratchpad variables in client scripts.

       g_form.setValue('field name', g_scratchpad.parent_number);

 

Thanks!

Sagar Pagar

The world works with ServiceNow

View solution in original post

6 REPLIES 6

Sagar Pagar
Tera Patron

I would suggest to use the display business rule to get the parents details and copied to g_scratchpad variables.

for example:

        g_scratchpad.parent_number = current.parent.number;

 

You can use these g_scratchpad variables in client scripts.

       g_form.setValue('field name', g_scratchpad.parent_number);

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Community Alums
Not applicable

Hi Sagar,

 

Actually there are other values as well which I need to populate from parent onload of this form.

Can you tell how to achieve that?

 

Community Alums
Not applicable

Now I have added the field Order_line_item in the form as below but the alert message above is giving different sys_ids not of the current record.

find_real_file.png

Hi Ankur,

 

You need to create a display business rule on Order Task table. You can refer this script as example.

 

Condition: current.isNewRecord() && !current.customr_order_line.nil()

 

	var parentDetails = current.customr_order_line.getRefRecord();

	if (parentDetails.isValidRecord()) {
		current.u_order_line_item = parentDetails.getUniqueValue(); // reference field		


		current.your_field1 = parentDetails.your_field1;
		current.your_field2 = parentDetails.your_field2;
	}

 

Thanks!

Sagar Pagar

The world works with ServiceNow