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

Community Alums
Not applicable

Your first answer was correct There was some syntax error at my side

Thanks for your support

 

I have one more query .

when I use scratchpad object from display BR and pass it on to Client script, it puts the same value again and again , even if the value is empty, it keeps on setting the old value.

Hi Ankur,

 

You have to check the condition in client script before putting values into fields.

for example:

    if (g_form.isNewRecord() || g_form.getValue('your_fields') == "") {

        g_form.setValue('your_field1', g_scratchpad.value1);
        g_form.setValue('your_field2', g_scratchpad.value2);
    }

 

Thanks!

Sagar Pagar

The world works with ServiceNow