Server JavaScript error Cannot find function approvers in object - Service Portal Error

Imran1
Giga Guru

Hi Team,

I am getting the below error message in my Service Portal

Server JavaScript error Cannot find function approvers in object [object application name].

I am unable to figure out what is causing this error message to appear. When verified in native view it seem to work fine.

 Below is my script - UI action - I even included first and last line from BR still no luck

(function executeRule(current, previous /*null when async*/) {

function approvers(value) {

var addApp = [];
var appr = new GlideRecord('sys_user');
appr.addEncodedQuery('nameIN' + value + '^ORemailIN' + value);
appr.query();
while (appr.next()) {
addApp.push(appr.getUniqueValue());
}
return addApp.toString();
}

var approver1 = current.add_app_1.getDisplayValue();
var approver2 = current.add_app_2.getDisplayValue();
var approver3 = current.add_app_3.getDisplayValue();
var approver4 = current.add_app_4.getDisplayValue();
var workflow = current.contract_stage;

if (workflow == '25') {
if (approver1 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Service Under Approver Tab');
else {
current.contract_stage = '32';
var a1 = this.approvers(approver1);
var finalApp = (a1 != '') ? a1 : approver1;
current.pending_approver = finalApp;
}
} else if (workflow == '34') {
if (approver2 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Additional Under Approver Tab');
else {
current.contract_stage = '36';
current.contract_status = '2';
var a2 = this.approvers(approver2);
var fina2 = (a2 != '') ? a2 : approver2;
current.pending_approver = fina2;
}
} else if (workflow == '38') {
if (approver3 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select S Approver Tab');
else {
current.contract_stage = '40';
current.contract_status = '2';
var a3 = this.approvers(approver3);
var fina3 = (a3 != '') ? a3 : approver3;
current.pending_approver = fina3;
}
} else if (workflow == '42') {
if (approver4 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select  Approver Tab');
else {
current.contract_stage = '44';
current.contract_status = '2';
var a4 = this.approvers(approver4);
var fina4 = (a4 != '') ? a4 : approver4;
current.pending_approver = fina4;
}
}

current.update();

})(current, previous);

 

Appreciate any help to resolve this.

Regards,
Imran

 

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

Hi,

To call approvers function, you can refer it without this object. Try the below code and see whether issue is resolved:

(function executeRule(current, previous /*null when async*/) {

function approvers(value) {

var addApp = [];
var appr = new GlideRecord('sys_user');
appr.addEncodedQuery('nameIN' + value + '^ORemailIN' + value);
appr.query();
while (appr.next()) {
addApp.push(appr.getUniqueValue());
}
return addApp.toString();
}

var approver1 = current.add_app_1.getDisplayValue();
var approver2 = current.add_app_2.getDisplayValue();
var approver3 = current.add_app_3.getDisplayValue();
var approver4 = current.add_app_4.getDisplayValue();
var workflow = current.contract_stage;

if (workflow == '25') {
if (approver1 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Service Under Approver Tab');
else {
current.contract_stage = '32';
var a1 = approvers(approver1);
var finalApp = (a1 != '') ? a1 : approver1;
current.pending_approver = finalApp;
}
} else if (workflow == '34') {
if (approver2 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Additional Under Approver Tab');
else {
current.contract_stage = '36';
current.contract_status = '2';
var a2 = approvers(approver2);
var fina2 = (a2 != '') ? a2 : approver2;
current.pending_approver = fina2;
}
} else if (workflow == '38') {
if (approver3 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select S Approver Tab');
else {
current.contract_stage = '40';
current.contract_status = '2';
var a3 = approvers(approver3);
var fina3 = (a3 != '') ? a3 : approver3;
current.pending_approver = fina3;
}
} else if (workflow == '42') {
if (approver4 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Approver Tab');
else {
current.contract_stage = '44';
current.contract_status = '2';
var a4 = approvers(approver4);
var fina4 = (a4 != '') ? a4 : approver4;
current.pending_approver = fina4;
}
}

current.update();

})(current, previous);

 

Thank you,
Palani

View solution in original post

2 REPLIES 2

palanikumar
Mega Sage

Hi,

To call approvers function, you can refer it without this object. Try the below code and see whether issue is resolved:

(function executeRule(current, previous /*null when async*/) {

function approvers(value) {

var addApp = [];
var appr = new GlideRecord('sys_user');
appr.addEncodedQuery('nameIN' + value + '^ORemailIN' + value);
appr.query();
while (appr.next()) {
addApp.push(appr.getUniqueValue());
}
return addApp.toString();
}

var approver1 = current.add_app_1.getDisplayValue();
var approver2 = current.add_app_2.getDisplayValue();
var approver3 = current.add_app_3.getDisplayValue();
var approver4 = current.add_app_4.getDisplayValue();
var workflow = current.contract_stage;

if (workflow == '25') {
if (approver1 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Service Under Approver Tab');
else {
current.contract_stage = '32';
var a1 = approvers(approver1);
var finalApp = (a1 != '') ? a1 : approver1;
current.pending_approver = finalApp;
}
} else if (workflow == '34') {
if (approver2 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Additional Under Approver Tab');
else {
current.contract_stage = '36';
current.contract_status = '2';
var a2 = approvers(approver2);
var fina2 = (a2 != '') ? a2 : approver2;
current.pending_approver = fina2;
}
} else if (workflow == '38') {
if (approver3 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select S Approver Tab');
else {
current.contract_stage = '40';
current.contract_status = '2';
var a3 = approvers(approver3);
var fina3 = (a3 != '') ? a3 : approver3;
current.pending_approver = fina3;
}
} else if (workflow == '42') {
if (approver4 == "" && current.need_additional_reviewer == true)
gs.addErrorMessage('Please Select Approver Tab');
else {
current.contract_stage = '44';
current.contract_status = '2';
var a4 = approvers(approver4);
var fina4 = (a4 != '') ? a4 : approver4;
current.pending_approver = fina4;
}
}

current.update();

})(current, previous);

 

Thank you,
Palani

Thank You Palani, It worked