Skip to content

Commit 57accca

Browse files
authored
Hide Related List based on Record
1 parent d28f9a1 commit 57accca

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Hide Related List if there is no Record
2+
3+
Script Type : Client Script, Type : OnLoad, Table: incident
4+
5+
Script Type : Script Include, Glide AJAX enabled : True, Role : admin
6+
7+
Goal : Hide the Related list on the form based on the record
8+
9+
Walk through of code : So the Client Script will run on the Onload form so this will check whether the mentioned related list has record or not so based on that this will send the data to the Script include through Glide Ajax and then this Script include will Glide Record to the particular table name and then check whether record/records it there or not based on that this will return 'true' if record is no record else return 'false' means there is a record.
10+
11+
![alt text](clientScript.png)
12+
![alt text](scriptInclude.png)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function onLoad() {
2+
3+
/*
4+
Inputs
5+
1. Related list name
6+
2. Table name which has been related to
7+
3. Field name through which relationship made
8+
9+
E.g.,
10+
1. Related list name - incident [Child Incidents]
11+
2. Table name which has been related to - incident [Incident]
12+
3. Field name through which relationship made - parent_incident [Parent Incident]
13+
14+
15+
Output
16+
If true = Hide the Related List
17+
Else = there is record won't hide the Related List
18+
19+
*/
20+
21+
// Related list that want to hide when there is no record in the related list records
22+
// Can add other related list as well this object is define as
23+
// {related_list_name :{table : table_related_to, ref: field_reference_to_the_table}}
24+
25+
var relatedList = {
26+
'task_sla': { table: 'task_sla', ref: 'task' },
27+
'incident' : {table : 'incident', ref: 'parent_incident'},
28+
'incident_task': { table: 'incident_task', ref: 'parent' }
29+
};
30+
31+
32+
// Called the function based on the list of related list in the object.,
33+
for (var listName in relatedList) {
34+
checkAndHideRelatedList(listName, relatedList[listName]);
35+
}
36+
37+
// function which is used to called the Script include through GlideAjax and check whether record is there are not and get the response based on that it will hide the related list.
38+
function checkAndHideRelatedList(listName, config) {
39+
var ga = new GlideAjax('CheckRelatedListRecord');
40+
ga.addParam('sysparm_name', 'hasRecord');
41+
ga.addParam('sysparm_related_table', config.table);
42+
ga.addParam('sysparm_reference_field', config.ref);
43+
ga.addParam('sysparm_record_sys_id', g_form.getUniqueValue());
44+
45+
ga.getXMLAnswer(function(answer) {
46+
if (answer == 'false') {
47+
g_form.hideRelatedList(listName);
48+
49+
}
50+
});
51+
}
52+
53+
}
110 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var CheckRelatedListRecord = Class.create();
2+
CheckRelatedListRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
// Glide Record to the particular table and then query and get the record and setlimit only for one record to avoid unnecessary querytime.
5+
hasRecord: function() {
6+
7+
var relatedTable = this.getParameter('sysparm_related_table');
8+
var referenceField = this.getParameter('sysparm_reference_field');
9+
var recordSysId = this.getParameter('sysparm_record_sys_id');
10+
11+
var gr = new GlideRecord(relatedTable);
12+
gr.addQuery(referenceField, recordSysId);
13+
gr.setLimit(1);
14+
gr.query();
15+
return gr.hasNext() ? 'true' : 'false';
16+
17+
},
18+
type: 'CheckRelatedListRecord'
19+
});
77.9 KB
Loading

0 commit comments

Comments
 (0)