Pull Assignment Group's Parent Name Using Onload Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 04:30 PM
Having trouble pulling the Assignment Group's Parent Name Using Onload Client Script for an Incident form. If the name exists, set the custom string field to True, otherwise set to false.
I am able to do successfully using a Business Rule, but I need to execute this using onLoad client script. Can anyone try to replicate and provide a successful working client script? When I tried, I would only get false regardless of the parent group name.
Here's the script for the business rule:
(function executeRule(current, previous /*null when async*/) {
// Check if the Assignment group's parent is 'Technology'
if (current.assignment_group.parent.name == 'Technology') {
// If the condition matches, set 'u_task_parent_group' to 'true'
current.u_task_parent_group = 'true';
} else {
// If the condition does not match, set 'u_task_parent_group' to 'false'
current.u_task_parent_group = 'false';
}
// current.update();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 04:46 PM
You can use a display business rule to set a g_scratchpad variable. And then access it in onLoad client script which makes it easier.
// Check if the Assignment group's parent is 'Technology'
if (current.assignment_group.parent.name == 'Technology') {
// If the condition matches, set 'u_task_parent_group' to 'true'
g_scratchpad.parent_group = 'true';
} else {
// If the condition does not match, set 'u_task_parent_group' to 'false'
g_scratchpad.parent_group = 'false';
}
For example g_scratchpad.parent_group can be set in BR and then use it in the onLoad script.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 04:52 PM
@kevin_munguia wrote:
but I need to execute this using onLoad client script
What's the reasoning for this? Changing from a BR to an onLoad client script has very different implications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 07:45 PM
You can move your logic to check whether assignment group parent is Technology or not to a Client Callable Script Include. Then, you can call your Script Include from a Client Script using a AJAX call in which you can manipulate your .u_task_parent_group field value using g_form.setValue() API.
An alternative way to this can be using the g_form.getReference() API. You can configure your On-Load Client Script as below :
function onLoad() {
//Type appropriate comment here, and begin script below
var assignmentGroup = g_form.getReference('assignment_group');
var parent = assignmentGroup.parent;
if (parent == 'sys_id of the parent i.e. Technology') {
g_form.setValue('u_task_parent_group', 'true');
} else {
g_form.setValue('u_task_parent_group', 'false');
}
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.