We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

passing data in related list create new

juan9
Giga Guru

Hello experts!

I want to pass some properties from the parent record to the child record, when a record is made through a related list.

 

 

goal:

on table A,

when I click on 'new' on the related list,

the parents records information should be passed to the child record.

 

 

here is the parent record::

note: see button 'New4'

find_real_file.png

note: I edited the name of the button so that I could look at the code.

 

here is the child record

find_real_file.png

right now, the field 'order_reference' is being passed to the child record.

I want to populate populate 'short_description' and 'description' from the parent record.

this is the code for the OOB button::

var uri = action.getGlideURI();
var path = uri.getFileFromPath() + '';
path = path.substring(0, path.length - 5) + '.do';

uri.set('sys_id', '-1');

path = checkWizard(uri, path);

if (path) 
   action.setRedirectURL(uri.toString(path));

action.setNoPop(true);

function checkWizard(uri, path) {
   var already = uri.get('WIZARD:action');
   if (already == 'follow')
   return null;
   
   var wizID = new GlideappWizardIntercept(path).get();
   if (!wizID)
      return path;
   
   uri.set('sysparm_parent', wizID);
   uri.deleteParmameter('sysparm_referring_url');
   uri.deleteMatchingParameter('sysparm_list_');
   uri.deleteMatchingParameter('sysparm_record_');
   uri.deleteParmameter('sys_is_list');
   uri.deleteParmameter('sys_is_related_list');
   uri.deleteParmameter('sys_submitted');
   uri.deleteParmameter('sysparm_checked_items');
   uri.deleteParmameter('sysparm_ref_list_query');
   uri.deleteParmameter('sysparm_current_row');
 
   uri.set('sysparm_referring_url', uri.toString());
   uri.deleteMatchingParameter('fancy.');
   uri.deleteMatchingParameter('sys_rownum');
   uri.deleteMatchingParameter('sysparm_encoded');
   uri.deleteMatchingParameter('sysparm_query_encoded');
   uri.deleteParmameter('sysparm_refer');

   return 'wizard_view.do';
}

the buttons sys_id is:: 7b37cc370a0a0b34005bd7d7c7255583

 

 

I have a client scripts on the child table that populates the fields when the 'order_reference' changes. The issue is that the script does not run when the record is opened through the related list.

I know I can do a BR to populate the fields, but I figure this is a great experience for learning how to use other ServiceNow functionality haha.

 

1 ACCEPTED SOLUTION

Kalyani Jangam1
Mega Sage

Hi, In onload client script of table, you can add below condition

function onLoad() {
   //Type appropriate comment here, and begin script below
    if(g_form.getValue('parent_incident') !='' && g_form.getValue('parent_incident') != null){// field name that create relationship
        alert("Client Script calls-------");
    }
   
}

 

Mark Helpful, if it will work

View solution in original post

1 REPLY 1

Kalyani Jangam1
Mega Sage

Hi, In onload client script of table, you can add below condition

function onLoad() {
   //Type appropriate comment here, and begin script below
    if(g_form.getValue('parent_incident') !='' && g_form.getValue('parent_incident') != null){// field name that create relationship
        alert("Client Script calls-------");
    }
   
}

 

Mark Helpful, if it will work