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

Josh Virelli
Tera Guru

Hi Yundlu,

I just recreated what you have done and I ran into an issue with line 27 in the Server script. Specifically "GlideTableDescriptor". That API is not supported in a scoped app. I found a confirmation that there is no Scoped alternative from a ServiceNow employee in this post 19 days ago:

 https://community.servicenow.com/community?id=community_question&sys_id=07a433e2dbd957003882fb651f96...

We don't have any official documentation around API's such as “GlideTableDescriptor” and “FilteredGlideRecord”.

If it is not on https://developer.servicenow.com/, then it is very likely unsupported.

Also, the API might work in global scope, but there is a restriction at the java layer so there IS NOT a way around it. 

Thanks,
- Lewis Chi
ServiceNow Engineer

I would recommend you clone the app in the Global scope and do your customizations there.

If my answer was helpful or answered your question, please mark it as 'Helpful' or 'Correct'

Thanks!

Josh

Thanks Josh!  I commented that line out and it still does not work.  Also I checked the HR scoped version of this widget (hri-ticket-attachments) and I see that API in there and it seems to work fine.  I'm wondering if there's something else in this code that's preventing it to render in scope...

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.

So, I went back to my cloned widget and took out all the ng-if's with canRead, canWrite, and canAttach and the widget now shows up...but I'm still confused why.

All of those API's work perfectly in global and in the HR scope, so I'm confused why those would prevent the cloned ticket attachment widget to not work in our custom scope.  Any thoughts?