- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 02:10 PM
Our team wants to use the ootb widget-ticket-attachments widget, but want to make some cosmetic changes. We cloned the widget in our scope, but it won't show up in the service portal. Are we missing something obvious to make this widget show up and work in scope?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 03:24 PM
Cloned widget has some small problems, which can be easy fixed.
First of all one should fix the lines (2-3) from
data.sys_id = input.sys_id || options.record_id || $sp.getParameter("sys_id");
data.table = input.table || options.record_table || $sp.getParameter("table");
to
data.sys_id = (input || {}).sys_id || options.record_id || $sp.getParameter("sys_id");
data.table = (input || {}).table || options.record_table || $sp.getParameter("table");
and then the line (28)
data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) && GlideTableDescriptor.get(data.table).getED().getAttribute("no_attachment") != "true";
to, for example, the following lines
function isTableAttributeEqualValue (tableName, attributeName, value) {
var gr = new GlideRecord("sys_schema_attribute_m2m");
gr.addQuery("schema.name", tableName); // "Dictionary Entry"."Table"
gr.addQuery("attribute.name", attributeName); // "Attribute"."Name"
gr.query();
return gr.next() && gr.getValue("value") === value && !gr.hasNext();
}
data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) &&
!isTableAttributeEqualValue(data.table, "no_attachment", "true");
In my tests, the cloned widget starts working after the changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 03:34 PM
Thanks! I just tested your solution and it indeed works! Can you explain why this works?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 03:41 PM
It's very easy. First of all input can be undefined and input.sys_id is unsafe. (input || {}).sys_id is safe.
The next problem: original code used GlideTableDescriptor method, which can't be used in scoped application. The method be used to test, whether the table data.table contains attribute no_attachment=true. I wrote replacement of the test, which don't use GlideTableDescriptor method. It's the second fix.