How to Get a Parent's Data to a New Record using a UI List Action

Joshua Cassity
Kilo Guru

We've run into an issue where we have a custom parent request form that has a related list and we'd like to add an action on that related list to create a new related record to this parent but copy over some of the parent's data over to the newly created record.

Ex. I have a Telecommunications Request Form that has basic data on it (Requested By, Telecommunication Closet Number, Type of Request, Service Code) and a related listing of Circuits that is derived based upon the Telecommunication's Closet Number.

I also have a Circuit table that has circuit specific data on it (Circuit Name, Power Type, Grid Name and also has a spot for the Telecommunication Closet Number for which it lives).

So in our case, Telecommunication Closet 45 already has three network circuits in it but I'd like to add a new circuit by letting the user press the New button on the related listing.

find_real_file.png

The problem is that when we create this new List UI Action, we can't seem to get the Closer # from the parent Request to put into the newly created child Circuit because we can't figure out how to collect and push that data to the new record. We believe this is because the action actually resides on the child Circuit form so anytime we do a 'current.' action it's not on the correct table and we end up getting this error message:

find_real_file.png

Can anyone provide us with a solution to actually be able to pull the parent's data into the child record using a List UI Action while allowing the user to input any other data into the new child record before it's saved to the database?

Any assistance would be greatly appreciated. Here is a copy of our logic so far:

// Open a new Glide Record in the circuit Table

var circuit = new GlideRecord('u_circuit');

circuit.initialize();

circuit.u_site_id = current.u_site_id; <<< Here's the Issue!

// Set the Form Fields Based Upon the NetTN Request Entered Data

circuit.insert();

action.setRedirectURL(circuit);

1 ACCEPTED SOLUTION

I think this is the issue.   Because it is a queried relationship there is no guarantee that it only has 1 parent so parent can't be provided.   Try this instead in a client ui action:



function insertNewCircuit() {


  document.location = 'u_circuit.do?sys_id=-1&sysparm_query=u_nettn_request=' + g_form.getUniqueValue() + '^u_site_id=' + g_form.getValue('location');


}



Screen Shot 2017-02-23 at 9.51.37 AM.png


View solution in original post

30 REPLIES 30

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Here is an example using incident and incident_task:



// Open a new Glide Record in the circuit Table


var task = new GlideRecord('incident_task');


task.initialize();



task.assigned_to = parent.assigned_to;


task.incident = parent.sys_id;



// Set the Form Fields Based Upon the NetTN Request Entered Data


task.insert();


action.setRedirectURL(task);


Make sure your ui action name starts with sysverb to avoid the popup.   And you'll want to make sure it is a related list with the   condition RP.isRelatedList() because parent won't be in scope on the main list.



Screen Shot 2017-02-22 at 7.44.10 PM.png


Unfortunately I've tried this and nothing happens at all. When the UI Action button is pressed, the screen refreshes but no circuit record is created and I'm redirected back to the parent form.



find_real_file.png


It doesn't event redirect you to a new circuit record?   It leaves you on the request form?


Correct.



~ J ~