Parent not available in UI action condition related list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2018 03:30 AM
Hi all,
Today I found myself dumbfounded again, always a good start on a Monday...
The case being:
I have 2 related lists, between the tables sn_hr_core_course_case and sn_hr_core_training.
I have created 2 relationships for this, 1 to get all the Course Cases when looking at a Training record:
And 1 to get all the available Training records when looking at a Course Case:
This all works perfectly so far!
Then I added 2 UI actions, for Enrolling Course Cases for a Training, but those should only show when looking a the related list AND if records are available in the related list.
I've asked a previous question about this and the way to go was an include script called from the UI-action-condition.
So here we are, UI Action 'Enroll for Training' on the HR Course Case table:
This one works like a charm! The button only shows when I'm in a Training record, looking at the related list to available HR Course Cases and my Training status = 1 and if the script include function returns True.
For completion, here's the script include function called:
getCases4Training: function(current) {
var gr = new GlideRecord('sn_hr_core_case_course');
gr.addQuery('u_course', current.u_course.u_course);
gr.query();
if (gr.next())
return true;
else
return false;
},
I was happy this worked, so I wanted the reverse one as well, when looking at a HR Course Case only show the button Enroll if Training records are available:
Again the condition to only show the button on the related list and if training records are found using a script include.
Script include function for completion:
getTrainings4Case: function(current) {
var gr = new GlideRecord('sn_hr_core_training');
gr.addQuery('u_course.u_course', current.u_course);
gr.addQuery('u_status', 1); //Open for enrollment
gr.query();
if (gr.next())
return true;
else
return false;
},
But...
This time the condition doesn't work!
For some reason the 'parent'-object doesn't exist now? So the condition fails and always shows the button...
Anyone with an idea why on earth the parent object is undefined for the second related list?
And preferably a way to fix it 🙂
I already found this post: Related list "parent" not working via conditions but that wasn't very helpful...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2018 04:07 AM
I could probably see a couple of ways to try to fix this:
1. In your relationship maybe you want to add a condition first to validate if parent really exists like:
if (parent) {
current.addQuery();
}
This means if parent doesn't exists, relationship won't modify the query.
2. On the condition of the UI action you can probably do something like:
RP.isRelatedList() && parent && new hr.....
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2018 04:22 AM
Hi Sergiu thanks for your reaction.
The problem isn't that I can't check if there is a parent available, the problem is that the parent should be available.
The relationships both work, as the related lists filter the way I intended them to.
The problem is in the UI action condition, where for the first list it works perfectly with the parent record, where the parent record isn't available in the second related list's UI action.
Cheers,
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2018 04:55 AM
And I found a solution to my problem, still doesn't explain why parent-object isn't available in the second related list, but what the hell, I can move on 🙂
Solution:
Apparently when using the 'current'-object in the condition of a related list, this record contains the data of the first(?) record in the related list. Therefor I can check if the current.sys_id is empty and if it is, there is no data in the related list.