how to fetch value of a related list record and according to that Hide/show the UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 04:53 AM
How to fetch value of a related list record and according to that Hide/show the UI action
For example: I have created a relationship between 2 tables. I want to check the related list field - result is empty, If it is empty then the UI action should be visible. otherwise it should not be visible.
UI action created on table - Input ola table
related list - ola score table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 05:31 AM
You need to write function in the script include as mentioned below:
showUIAction: function(current) {
var relatedTable = new GlideRecord("related_table_Name");
relatedTable.addQuery("parent_table_field", current.sys_id);
relatedTable.query();
if(relatedTable.getRowCount() > 0){
return "false";
}else{
return "true";
}
},
And from the UI action, you need to call the script include as below:
new scriptIncludeName().functionName(current) == "true"
I hope you get the idea how to implement it!
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 08:33 AM
Thank You So Much for your help @Prince Arora it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 08:40 AM
You marked my answer helpful!
Please Accept it if it has answered you query, It would be helpful for future readers too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 11:28 AM - edited 04-14-2023 11:32 AM
It is possible to do Related List queries via "addEncodedQuery" strings in Business Rules and/or Scheduled Jobs using "RLQUERY"
This script is an example of the syntax structure that I'm running in a scheduled job:
TriggerNotificationNew();
function TriggerNotificationNew() {
var getAsset = new GlideRecord('alm_hardware');
getAsset.addEncodedQuery('u_workstation_type=BCA^install_status=1^RLQUERYu_bca_health_check_log.u_asset_record,>=1^sys_created_onRELATIVELT@dayofweek@ago@60^ENDRLQUERY'); //* includes related list query
getAsset.query();
var list = [];
while(getAsset.next()) {
list.push(getAsset.serial_number.toString());
}
var arrayUtil = new ArrayUtil();
var answer = arrayUtil.unique(list);
var getSNval = new GlideRecord('alm_hardware');
getSNval.addQuery('serial_number', 'IN', answer);
getSNval.query();
while (getSNval.next()) {
gs.eventQueue('send.bcahealthcheck.reminder', getSNval, getSNval.serial_number); //* would push the Serial Number as Parm1
}
}
It starts with the "RLQUERY" piece and then ends with the "ENDRLQUERY" piece