Issue calling Script Include from a UI Action

David165
Mega Expert

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

1 ACCEPTED SOLUTION

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.

find_real_file.png

 

Kind regards,
Łukasz

 

View solution in original post

12 REPLIES 12

Hi Lukasz

Pre-pending the scope name gives this error:

Evaluator: org.mozilla.javascript.EcmaError: "x_173342" is not defined. 

Also, if I prepend the scope and application name "x_173342_myapp" I get the same error.

Regards

David

 

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.

find_real_file.png

 

Kind regards,
Łukasz

 

David165
Mega Expert

Hi Lukasz

 

You nailed it! Many, many thanks, it's working fine now and doing exactly what I wanted.

On to the next challenge 🙂

 

Regards

 

David