Tree Picker - Grouping 'Assignment Groups' but making parent unselectable (cannot assign work).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2016 10:09 AM
Hello,
I am trying to group Assignment Groups within the Tree Picker but want it so the 'parent' is not able to be selected but the children can be selected. Unfortunately if you uncheck the "Assign Work" box, under the group settings, it and all children groups become hidden within the Tree Picker. (See image for an example.)
I have tried setting a condition within the 'Assignment Group' field but was not successful (See attached file). I am also not sharp enough to modify the code below (from article Tree Picker group selection ) as business rule that will tell the user to select a child group when they accidentally select a parent group.
(function executeRule(current, previous /*null when async*/) {
current.your_field_name_here.setError("Please select a service, rather than a category.");
action.setRedirectURL(current);
current.setAbortAction(true);
})(current, previous);
Anyone have a solution or workaround or assist me the Business Rule code that could be used?
Thank you,
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2016 05:41 PM
Hi Wesley,
One of the workaround I have done is (using a single onChange Client Script), when the user selects the parent-choice, I check if the it's "parent" value has any info or empty.
For instance,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var selected_item = g_form.getReference('u_my_test_field', callBackFunction); //recommended to use call-back function when using g_form.getReference method
}
function callBackFunction(field_parameter) { //reference is passed into callback as first arguments
if (field_parameter.u_parent == '') { //custom field where I store the parent value
alert("You cannot select Parent item, select the children");
g_form.setValue('u_my_test_field', '');
return;
}
}
At least the script prevents user from selecting the parent choice, should give you an idea.
Let me know how you go.
Thanks,
Samiul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2017 09:56 PM
Hi Samiul,
Sorry, I thought that I responded back to you.
Here is the Client Script that I ended up with and it is working good, but not positive if it is a bad method or not; best practice. As you mentioned maybe I should be doing a call-back function...?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var grp = new GlideRecord('sys_group_has_role');
grp.addQuery('group', newValue);
grp.query();
if(!grp.next()){
alert("This Assignment Group has no role(s), you cannot assign to this Parent group. Please select a Sub/Child group.");
g_form.clearValue('assignment_group');
}
}
Thanks again and sorry for not responding back.
-Wesley