How to call script include from server script

Mi4
Tera Expert

Hello
please tell me.
I want to call a script include in the widget server script.

I can now call the script include, but the contents of the script include are not running.

(Script include can be executed by itself, so I guess I have a problem writing the script include and the calling part of the server script)

How should I write?

 

There are two points I want to call.
(1) If the conditions are met, turn the flag ON.

(2) If the conditions are met, update the record.

Script Include:
(1)
find_real_file.png
(2)
find_real_file.png

Server Script:
(1)

var geFlg = new sn_hr_le.GetOBRecord().flugOn();
(2)

var geFlg2 = new sn_hr_le.GetOBRecord().updateVariables();


Thanks in advance,

1 ACCEPTED SOLUTION

Hi,

The script include call will be like Ankur mentioined in previous comment.

var geFlg = new sn_hr_le.GetOBRecord().flugOn(sysApprovalRecord);

One thing I noticed in script include is that the script you have is a client callable one but your client callable check box in unchecked. The client callable checkbox should be unchecked if you are calling the script include from server side. So you need to update your script, Please try using the below script include.

var GetOBRecord = Class.create();
GetOBRecord.prototype = {
	initialize: function() {
	},
	flugOn: function(sysApprovalRecord){
		var cse = new GlideRecord('sn_hr_le_case');
		cse.addQuery('sys_id', sysApprovalRecord.document_id);
		cse.addQuery('hr_service', 'eb0e5456dbc41010e6b98a184896192d');
		cse.addQuery('le_progress', 'Approver Waiting');
		cse.setLimit(1);
		cse.query();
		return cse.hasNext();
	},
	type: 'GetOBRecord'
};

 

Now, coming to your query

I want to use or update a widget's record within a script include, is that not possible? - Yes you can update a record in a script include, but if you want to display something only on the widget and don't want to save it then you need to have a code in widget's client side script and angular/html.

Kindly mark my answer as Correct and helpful based on the Impact.

Regards,

Alok

View solution in original post

10 REPLIES 10

Hi,

 

If you don't want to update then don't update but return true from script include and check in widget server script and based on that you can do your operation.

 

Thanks,

Kunal

Hi,

Exactly what I want to do!

How should I write if I want to update the widget side?

Regards,

Hi,

call it like this; pass the glide record object

var geFlg = new sn_hr_le.GetOBRecord().flugOn(sysApprovalRecord);

update script include code as below:

var cse = new GlideRecord('sn_hr_le_case');
cse.addQuery('sys_id', sysApprovalRecord.document_id);
cse.addQuery('hr_service', 'eb0e5456dbc41010e6b98a184896192d');
cse.addQuery('le_progress', 'Approver Waiting');
cse.setLimit(1);
cse.query();
return cse.hasNext();

if(geFlg){

 data.needDate = true;

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

Unreachble Code..Is the code different? 

find_real_file.png

 

Please tell me one more thing.

I want to use or update a widget's record within a script include, is that not possible?

 

Regards,

Hi,

The script include call will be like Ankur mentioined in previous comment.

var geFlg = new sn_hr_le.GetOBRecord().flugOn(sysApprovalRecord);

One thing I noticed in script include is that the script you have is a client callable one but your client callable check box in unchecked. The client callable checkbox should be unchecked if you are calling the script include from server side. So you need to update your script, Please try using the below script include.

var GetOBRecord = Class.create();
GetOBRecord.prototype = {
	initialize: function() {
	},
	flugOn: function(sysApprovalRecord){
		var cse = new GlideRecord('sn_hr_le_case');
		cse.addQuery('sys_id', sysApprovalRecord.document_id);
		cse.addQuery('hr_service', 'eb0e5456dbc41010e6b98a184896192d');
		cse.addQuery('le_progress', 'Approver Waiting');
		cse.setLimit(1);
		cse.query();
		return cse.hasNext();
	},
	type: 'GetOBRecord'
};

 

Now, coming to your query

I want to use or update a widget's record within a script include, is that not possible? - Yes you can update a record in a script include, but if you want to display something only on the widget and don't want to save it then you need to have a code in widget's client side script and angular/html.

Kindly mark my answer as Correct and helpful based on the Impact.

Regards,

Alok