- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 05:21 AM
Hi
Having got my UI Action to successfully create a child record and store the reference to the Parent, my next task is to generalize the code to create the child so I can call it from different forms.
I modeled my new UI Action and Script include in the community thread
https://community.servicenow.com/community?id=community_question&sys_id=96da8b6ddb5cdbc01dcaf3231f9619a6
My script include has this code:
var commentCreate = Class.create();
commentCreate.prototype = {
initialize: function(parent) {
this.parent = parent;
},
createcomment: function() {
var inst = new GlideRecord("x_173342_cicsv_t1_comment");
// Set the parent to point to the Project record
inst.setValue("u_parent_statement", this.parent);
// Insert new comment record
inst.insert();
// Takes us to that new record
// action.setRedirectURL(inst);
return(inst);
},
type: 'Comment create'
};
and the UI Action is:
var newComment = new commentCreate(current.sys_id);
var comment = newComment.createcomment();
action.setRedirectURL(comment);
The UI Action is not set client callable because
1. I figured the script include was executed on the server.
2. The example I modeled this on didn't specify this.
I have tried setting it client callable, but this didn't fix the issue.
When I click the button to fire the UI Action I see this in the debug log:
4:02:04.615: Evaluator: org.mozilla.javascript.EcmaError: "commentCreate" is not defined. Caused by error in sys_ui_action.0cb17749db2633008f1daf26489619a2.script
So it can't see my script include class in the UI Action.
This looks similar to a problem I reported having a week or so ago where I was unable to call any function I'd tried to "share" throughout the application, either using onLoad or script includes. I didn't manage to resolve that issue which has similar symptoms, the called function can't be found.
What have I done wrong?
David
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 08:21 AM
Hi David,
I have just noticed one thing in your screen, please look at what I have marked. Name of the class, prototype and type must have exacly the same name. This is the reason why you can not call it. Correct the names and also type and try to use it, if in the same application scope you should not need a prefix. Also do not use spaces in Script Include names.
Kind regards,
Łukasz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 07:34 AM
Hi
I've set my include script to be available in all application scopes:
and I've updated the UI Action to instantiate a global object:
var newComment = new global.commentCreate(current.sys_id);
But that gives the following error in the log:
Evaluator: org.mozilla.javascript.EcmaError: undefined is not a function. Caused by error in sys_ui_action.0cb17749db2633008f1daf26489619a2.script
If I remove the "global." I get the original error that commentCreate is not defined.
One question. Is the Name of the Include Script and the resulting name of the API, in any way connected to call to instantiate the object? I noted that my script is called "Create comment" (with a space) and the API name is "x_000000.Comment create", also with a space.
Is this relevant?
Regards
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 07:48 AM
//Since your SI is in the scope use the API name to instatiate the object.
// please replace with the correct name. Adjust the name of the SI with no spaces. That will give a new API name.
var newComment = new x_000000.Comment_create(current.sys_id);
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 07:01 AM
Hello David,
please check the below link
As you are working in scoped application, you need to specify Application scope while calling the script include.
Please mark answer correct if you find it as helpful.
Thanks,
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 08:02 AM
Hi Abhishek,
But from that document I read:
Calling a local script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 07:03 AM
Hi David,
In what scope have you created your Script Include? If this is a scoped Script Include and you try to call it outside of the scope then you need to call it with scope_name.class_name or if this is a global script include used in scoped appliation then global.class_name.
E.g. assuming that your scope is x_173342
var newComment = x_173342.commentCreate(current.sys_id);
or for global scope
var newComment = global.commentCreate(current.sys_id);
Also check if your script include is accessible for other applications
Hope this helped.
Kind regards,
Łukasz