- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 08:26 AM
So I'm working on what I thought might be a simple feature: Require a user to add Change Tasks before a Change Request can be submitted for approval (via a Request For Approval UI Action).
I have Change Tasks as an embedded list on my Change Request form and my users love it. So I'm wondering if I could key the UI Action visibility or at least have a client script check onSubmit (of the change request) if data has been populated in that embedded related list. Everything I see on the GlideList2 wiki page seems to be altering the properties of the embedded related list, and not actually interacting with its data.
Am I barking up the wrong tree here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 11:39 AM
Ok, with the insights Travis Toulson and Cory Seering gave me, I cracked the case.
function onSubmit() {
var list = GlideList2.getByName('change_request.change_task.change_request'),
rows = list.table.getElementsBySelector('tr.list_row'),
sys_id;
// - 1 to exclude the insert row which is the last in the list of rows retrieved above
if (rows.length - 1 == 0){
alert("No Change Tasks");
} else {
alert(rows.length + " up in here.");
}
}
Now all that's left to do is integrate this into my Request Approval button and I'm off to the races. Which leaves one more order of business for Travis and Chris:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 10:00 AM
Hi Robert,
Documentation is pretty thin on this other than to say that g_list is not available to related list UI Actions, only regular lists. So I did some code dumpster diving and came up with this hack, use it in a Client Script or Client Side UI Action:
function getEmbeddedListByTableName(tableName) {
var it,
list;
for (it in GlideLists2) {
list = GlideLists2[it];
if (list.tableName == tableName && list.isEmbedded()) {
return list;
}
}
}
alert('Total rows in embedded list: ' + getEmbeddedListByTableName('change_task').totalRows);
if (getEmbeddedListByTableName('change_task').totalRows == 0) {
alert('Dont do it!');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 10:29 AM
I'm wondering if my use of embedded related list is going to wreck this approach. I entered a Change Task new from the embedded list and hit submit but the .totalrows still ended up being 0. Came back to the form later and ran the onsubmit script and it was now 1 (since the record had been saved after)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 11:52 AM
Didn't notice that before but you're right. We need a live count. This version is sadly a little more tightly coupled to the DOM code but it picks up the live changes on the form. I'm not seeing counts anywhere else:
function getEmbeddedListByTableName(tableName) {
var it,
list;
for (it in GlideLists2) {
list = GlideLists2[it];
if (list.tableName == tableName && list.isEmbedded()) {
return list;
}
}
}
alert('Total rows in embedded list: ' + getEmbeddedListByTableName('change_task').table.getElementsBySelector('tr.list_row').length - 1);
if (getEmbeddedListByTableName('change_task').table.getElementsBySelector('tr.list_row').length - 1 == 0) {
alert('Dont do it!');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 10:23 AM
Based on our twitter conversation with @SNCory I have revised the code:
if (GlideList2.getByName('change_request.change_task.parent').grandTotalRows == 0) {
alert('Dont do it!');
}
Using the above scripts can still help you find the right List name for the getByName function.