- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 09:25 AM
We have a request to indicator if attachments exist on a change request that is being displayed at CAB utilizing CAB Workbench. Currently, CAB Workbench has no indicator if attachments exist. After searching for like solutions and opening a case with ServiceNow, it appears CAB Workbench is a portal will not use code like the Platform/Legacy UI.
For example, I have tried:
var chg_attach_cnt = new GlideRecord("sys_attachment");
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 01:16 PM
ServiceNow provided this solution-
function onLoad() {
var chg_id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "change_request");
gr.addQuery("table_sys_id", chg_id);
gr.query(function(response){
if (response.next()){
g_form.showFieldMsg('number', "Has attachment(s)", "info", false);
}
});
}
With the additional detail of:
1 - We discourage GlideRecord on the client in favour of REST and or the scratchpad on the server side.
2 - The GlideRecord code only work in UI16 because it's forgiving, as we can see the warning in console:
***WARNING *** GlideAjax.getXMLWait - synchronous function - processor: AJAXGlideRecord
*** WARNING *** GlideRecord synchronous query for table: sys_attachment
3 - Service Portal does not support synchronous ajax calls, so the call was never made.
We've refactored you code to support both UI16 and SP, but we highly suggest using a better method and not clientside GlideRecord.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 01:16 PM
ServiceNow provided this solution-
function onLoad() {
var chg_id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "change_request");
gr.addQuery("table_sys_id", chg_id);
gr.query(function(response){
if (response.next()){
g_form.showFieldMsg('number', "Has attachment(s)", "info", false);
}
});
}
With the additional detail of:
1 - We discourage GlideRecord on the client in favour of REST and or the scratchpad on the server side.
2 - The GlideRecord code only work in UI16 because it's forgiving, as we can see the warning in console:
***WARNING *** GlideAjax.getXMLWait - synchronous function - processor: AJAXGlideRecord
*** WARNING *** GlideRecord synchronous query for table: sys_attachment
3 - Service Portal does not support synchronous ajax calls, so the call was never made.
We've refactored you code to support both UI16 and SP, but we highly suggest using a better method and not clientside GlideRecord.