Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Hide Related List if there is no Record

Script Type : Client Script, Type : OnLoad, Table: incident

Script Type : Script Include, Glide AJAX enabled : True, Role : admin

Goal : Hide the Related list on the form based on the record

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.

![alt text](clientScript.png)
![alt text](scriptInclude.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function onLoad() {

/*
Inputs
1. Related list name
2. Table name which has been related to
3. Field name through which relationship made

E.g.,
1. Related list name - incident [Child Incidents]
2. Table name which has been related to - incident [Incident]
3. Field name through which relationship made - parent_incident [Parent Incident]


Output
If true = Hide the Related List
Else = there is record won't hide the Related List

*/

// Related list that want to hide when there is no record in the related list records
// Can add other related list as well this object is define as
// {related_list_name :{table : table_related_to, ref: field_reference_to_the_table}}

var relatedList = {
'task_sla': { table: 'task_sla', ref: 'task' },
'incident' : {table : 'incident', ref: 'parent_incident'},
'incident_task': { table: 'incident_task', ref: 'parent' }
};


// Called the function based on the list of related list in the object.,
for (var listName in relatedList) {
checkAndHideRelatedList(listName, relatedList[listName]);
}

// 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.
function checkAndHideRelatedList(listName, config) {
var ga = new GlideAjax('CheckRelatedListRecord');
ga.addParam('sysparm_name', 'hasRecord');
ga.addParam('sysparm_related_table', config.table);
ga.addParam('sysparm_reference_field', config.ref);
ga.addParam('sysparm_record_sys_id', g_form.getUniqueValue());

ga.getXMLAnswer(function(answer) {
if (answer == 'false') {
g_form.hideRelatedList(listName);

}
});
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var CheckRelatedListRecord = Class.create();
CheckRelatedListRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {

// Glide Record to the particular table and then query and get the record and setlimit only for one record to avoid unnecessary querytime.
hasRecord: function() {

var relatedTable = this.getParameter('sysparm_related_table');
var referenceField = this.getParameter('sysparm_reference_field');
var recordSysId = this.getParameter('sysparm_record_sys_id');

var gr = new GlideRecord(relatedTable);
gr.addQuery(referenceField, recordSysId);
gr.setLimit(1);
gr.query();
return gr.hasNext() ? 'true' : 'false';

},
type: 'CheckRelatedListRecord'
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.