How to acces variables from parent table to child table where both are in diffrent scope
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 01:39 AM
I have i record producer by which i am creating a record in x_sone2_ table which is in giso scope and i am creting child task for this in table sn_customerservice_task table which is in scope customerservice and i want to show the variables from parent table x_sone2_ to sn_customerservice_task this child record and i am using the formater and OOB ui macro com_glideapp_questionset_default_question_editor. but i am unable to show the varibles from parent record to the child record.
Could any one help?
Thanks in Advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 10:34 AM
According to the above mentioned, what I understood is, the issue you're facing seems to be related to displaying variables from a parent record (in your x_sone2_ table) onto a child task record (in the sn_customerservice_task table). You've mentioned using the com_glideapp_questionset_default_question_editor UI macro, but it seems like it’s not working as expected to display the parent record variables.
I would request you to break it down and see what could be causing the problem and how to fix it.
Key Concepts:
- Record Producer: Creates a record in the x_sone2_ table and initiates the child record in sn_customerservice_task.
- Variables: These are part of the Record Producer, but in your case, they are stored in the parent record (x_sone2_) and need to be displayed in the child record (sn_customerservice_task).
- UI Macro (com_glideapp_questionset_default_question_editor): This is used to display questions/variables dynamically in a form.
Approach to Display Variables from Parent to Child
To pass variables from a parent record (created via the record producer) to a child record, you need to ensure that:
- The variables from the parent record (x_sone2_) are accessible in the child record (sn_customerservice_task).
- You use a scripting approach (e.g., in a Business Rule, Script Include, or UI Script) to fetch and display those variables.
Solution Steps:
- Store Parent Variables in Child Record
You need to ensure that the child record (sn_customerservice_task) is receiving the variable values from the parent record (x_sone2_) when it’s created.
- Option A: Script in Record Producer
After the child task (sn_customerservice_task) is created, you can update the child task record with the values of the parent variables.
Here’s a simple server-side script you can add to the Record Producer:
// Script in Record Producer
var parentRecord = current; // Current record in the Record Producer (x_sone2_)
var childTask = new GlideRecord('sn_customerservice_task');
// Insert child task
childTask.initialize();
childTask.short_description = parentRecord.short_description; // Example of passing data
childTask.variables.parent_variable = parentRecord.variables.parent_variable; // Map your variables
childTask.insert();
- Option B: Business Rule on sn_customerservice_task
You can create a Business Rule on sn_customerservice_task to automatically populate the task with data from the parent record when the task is created:
(function executeRule(current, previous /*null when async*/) {
var parentRecord = new GlideRecord('x_sone2_');
if (parentRecord.get(current.parent_record_reference)) {
// Assuming 'parent_record_reference' is the field referencing x_sone2_ in the task
current.variables.parent_variable = parentRecord.variables.parent_variable; // Example of passing data
}
})(current, previous);
- Make Sure Variables Are Visible
After you've passed the values to the child task, you will need to display them. Here’s how you can display those variables on the task record using the UI Macro.
- You are already using the OOTB UI Macro (com_glideapp_questionset_default_question_editor), but it may not be working because the macro may not automatically recognize variables from a parent record.
Instead, ensure that the variables are mapped to fields in the child record (sn_customerservice_task) using a Reference Field or Custom Fields in the child task that pull the values from the parent.
- Using UI Macro to Display Variables
Once the variables are saved in the child record, use a UI Macro to display them in the form. The UI Macro will render the child record’s form, including the variables.
- Ensure that the variables in the child task (sn_customerservice_task) are correctly populated and mapped to fields.
- Use questionset or other UI macros to dynamically render the variables from the child record's field. For example:
<div>
<h3>Parent Variables</h3>
<p>Variable 1: ${task.variables.parent_variable}</p>
</div>
- Test in Form Layout
Once you have ensured that the parent variables are passed correctly to the child record:
- Check the task form layout and make sure the field for the variables is visible.
- Test by creating a record via the Record Producer and see if the child task gets populated with the parent variables.
Troubleshooting
- Check Variable Mappings: Make sure the variable names are correct and that they match in both the parent and child tables.
- Permissions: Ensure the user has permission to access the variables or fields you're trying to display.
- UI Macro Compatibility: If the UI Macro is not working, ensure it's rendering the right field and make sure you're calling it with the correct parameters.
- Async Handling: If you’re creating records asynchronously, make sure the parent record data is available when the child task record is created.
To display variables from the parent record (x_sone2_) in the child task record (sn_customerservice_task):
- Pass the variables from the parent record to the child record using a Record Producer script or Business Rule.
- Ensure variables are mapped correctly in the child record.
- Use the UI Macro to display the passed variables in the child record form.