Setting field values on the basis of parent table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 08:28 AM
Hi all,
I need to set some field values on the form which shall come from it's parent table when we click on new.
I am thinking to run onload client script but not sure what to write.
getReference will be used here i think.
As soon as new form open some fields should has values same as it's parent table.
Kindly help.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 08:57 AM
Hi @Udit5,
You have to use the display business rule on you child table. Take the parent field/column values into g_scratchpad variables.
In onload Client scripts assign/ set Values in your child table if its new record.
Take a look at below sample scripts -
Display BR: Get Parent Values of Incidents to Incident tasks
Condition: current.isNewRecord() && !current.incident.nil()
(function executeRule(current, previous /*null when async*/) {
var parentInc = current.incident.getRefRecord();
if (parentInc.isValidRecord()) {
current.cmdb_ci = parentInc.cmdb_ci;
current.assignment_group = parentInc.assignment_group;
current.description = parentInc.description;
current.priority = parentInc.priority;
}
})(current, previous);
On-load Client Scripts:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.isNewRecord()) {
g_form.setValue('cmdb_ci', g_scratchpad.cmdb_ci);
g_form.setValue('assignment_group', g_scratchpad.assignment_group);
g_form.setValue('description', g_scratchpad.description);
g_form.setValue('priority', g_scratchpad.priority);
}
}
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 09:14 AM
Well, busines rule or client script are options, but if you want , having some prepolutated values, better use defaul values on the field configuration. This will prepopulate your fields, but the user still can change that data.