Cloning widget-ticket-attachments widget in scope doesn't work

yundlu316
Kilo Guru

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?

1 ACCEPTED SOLUTION

Oleg
Mega Sage

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.

View solution in original post

6 REPLIES 6

Thanks!  I just tested your solution and it indeed works!  Can you explain why this works?

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.