Applying Template on Projects in Custom/Scoped Application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2015 11:38 PM
Hi,
We are extending the project table and project tasks tables. We want to apply template on these extended tables. However, When we try to apply template through scripts, We are getting an error "com.glide.script.fencing.MethodNotAllowedException: Function applyTemplate is not allowed in scope". It works fine when we manually go and apply templates. Can anyone help on this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2017 08:26 AM
paablo, do you know if this is something that has been introduced in Istanbul as an extension to the Scoped API, or whether it should always have been available? I'm having the same issue where this code is working in Istanbul, but not in Helsinki.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2017 04:12 PM
Running through the same issue. It would really be great if you could share the name of the script include with the applyTemplate function, and also clarify if There is a need to update the global script to be accessible by the custom/scopped app? Or should there be a mediator scripts in global to make all the required function calls?
Just interested to see your views and how your solutions work, and also evaluate the options for best design and future upgradability.
Best regards,
Nabil O.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 01:11 AM
See OOB Script Include "TemplateUtil"
sys_script_include.do?sys_id=166853320f130000b12e6903cfe0129d
var TemplateUtil = Class.create();
TemplateUtil.prototype = {
initialize: function(){
},
getApplicable: function(table) {
var t = new GlideTemplate();
var gr = t.getApplicable(table);
return gr;
},
apply: function(name, gr) {
var t = new GlideTemplate().getByName(name, gr.getTableName(), true);
if (t != null)
t.apply(gr);
return gr;
},
type: "TemplateUtil"
}
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 03:32 PM
Hi Paul,
Thanks a lot for your reply, but i couldn't actually see how to fit the 2 (the proposed function applyTemplate, and this one in the global templateUtil).
my question is on the line 16 [t.apply(gr);] which should call the application of the template. and that's what we are trying to hack to allow for the application of scoped templates. and the other challange is that it doesn't actually work manually for me to first save-as-templates in scope, i get the error (Not a project object).
Best regards,
Nabil O.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 05:33 PM
So you are trying to save a record as a template via code, rather than just apply an existing one to a record?
Using the normal GlideRecord API definitely won't work, as 'create' is not allowed in scoped apps for that table.
Based on this, it might not even be possible to do programmatically.
This does seem kind of silly, because it is possible to do manually.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022