Accessing parent form data in the child form client script

pragathitadiset
Tera Contributor

Hello Friends,

In the ITBM module, we have a demand task form. I am going to create the work order under the demand task. I need to populate the demand task form short description field value to the short description in the work order form. In the work order form I have a filed with the name parent. For your reference I am attaching the screen shot of it. Can any one suggest is it possible by client script?. If means could you please let me know how can get the data of parent in the child form client script. 

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

write an onload client script on work order:

 

var desc = g_form.getReference('parent',func);

function func(desc)

{

g_form.setValue('short_description',desc.short_description);

}


Raghav
MVP 2023

View solution in original post

4 REPLIES 4

RaghavSh
Kilo Patron

write an onload client script on work order:

 

var desc = g_form.getReference('parent',func);

function func(desc)

{

g_form.setValue('short_description',desc.short_description);

}


Raghav
MVP 2023

This works except is you are trying to retrieve a user from Parent User field.   Do you have an example if I am trying to retrieve the Assigned To from reference field.  The reference field is an incident number.  I want to get the Assigned To from the Incident.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Couple of approaches

1) use before insert BR on work order table

Condition: current.parent != ''

Script:

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

    // Add your code here

current.short_description = current.parent.short_description;

})(current, previous);

OR

2) onLoad Client Script

function onLoad(){

if(g_form.isNewRecord()){

var ref = g_form.getReference('parent', callBackMethod);

}

function callBackMethod(ref){

if(ref.short_description){

g_form.setValue('short_description',ref.short_description);

}

}

}

Regards
Ankur

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

@pragathihsn@gmail 

I would suggest to use before Insert BR if user doesn't wish to see the value on the form during creation

Regards
Ankur

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