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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

line number 4 contains which approval record? also you just need to return true/false and based on that set data.needDate as true or false

Can you share widget script here?

Regards
Ankur

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

Hi,

Thank you for your comment. 

In line number 4, there is the approval record information of the acquired target.

 

My widget server script Below: 

(function() {

var ACTION = 'updateApprovals';
var REJECTSTATE = 'rejected';
var APPROVEDSTATE = 'approved';
var REQUESTEDSTATE = 'requested';


if (input && input.action == ACTION) {
approvalRecord = getApprovalInfo(input.approvalId);
if (updateApproval(input.request))
getPostApprovalInfo();

} else if (options && options.sysId) {
data.approvalId = options.sysId;
data.isPosted = false;
data.approvalComments = "";
data.needDate = false; // add
var approvalRecord = getApprovalInfo(data.approvalId);
if (approvalRecord.state != REQUESTEDSTATE) {
data.isPosted = true;
getPostApprovalInfo();
}

}
//This function gets ShortDescription of the parent case.
function getApprovalInfo(sysId) {
var sysApprovalRecord = new GlideRecord('sysapproval_approver');
if (sysApprovalRecord.get(sysId)) {
data.shortDescription = sysApprovalRecord.sysapproval.short_description;
data.approvalText = gs.getMessage("Do you want to approve the {0}?", data.shortDescription);
// Add start
var getFlg = new sn_hr_le.GetOBRecord().flugOn();
gs.info(getFlg);
/*
// Replace Acript Include Start -->
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();
if (cse.next()) {
data.needDate = true;
}
// Replace Script Include End<--
*/
//Add end
} else
gs.addErrorMessage(gs.getMessage("Unexpected action occurred"));
return sysApprovalRecord;
}

 

Regards,

Kunal Varkhede
Tera Guru

Hi,

 

Change you script like below

while(cse.next())

{

cse.needDate = 'true';  //change data to cse 

cse.update();

return 'true';

}

 

Thanks,

Kunal

Hi,

Thank you for advice.

Is it OK to fix the script include? 

And I don't want to update the cse record, but want to set the widget to true.

 

Regards,