com.glide.script.RhinoEcmaError: Unexpected token: u

ujjwala_678
Tera Contributor

Hello All,

I have a catalog item in scoped appliacation which does attachment validation prior attaching to the variable using Onsubmit CS and script include, both works fine in native UI but it throws an error in sp saying -There is a javascript error in your browser console,

Could anyone please suggest me where should I make changes, to fix this issue?

Onsubmit CS:

function onSubmit() {
var actionName = g_form.getActionName();
if (g_form.getValue('submitted') == 'yes') {
 
return true;
}
var cat_id = g_form.getValue('_file_here');
alert(cat_id);
var ga = new GlideAjax('validateheaders');
ga.addParam('sysparm_name', 'validate');
ga.addParam('_file_here', cat_id);
ga.getXML(ajaxResponse);

function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer == 'false') {
g_form.addErrorMessage('Invalid data');


} else {

g_form.setValue('submitted', 'yes'); // set the hidden value to prevent recursion
 
g_form.getControl('oi_order_now_button').click(); // use HTMLElement to grab the button, then use click()
g_form.orderNow(actionName); //Use OrderNow or AddToCart
return true;
}


}
return false;
}
Script Include:
var validateheaders = Class.create();
validateheaders.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
validate: function() {
var attachmentSysID = this.getParameter('please_provide_your_file_here');
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(attachmentSysID);
var parser = new sn_impex.GlideExcelParser();
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();

var mandatoryHeaders = ["NAME", "NUMBER", "DATE", "CREATION_DATE", "LOOKUP_CODE"];

var isValid = true;

while (parser.next()) {
var row = parser.getRow();

for (var header in mandatoryHeaders) {
var currentHeader = mandatoryHeaders[header];

// Check if the header is present in the column headers
if (headers.indexOf(currentHeader) === -1) {
isValid = false;
 


}
// Check if the value in the mandatory column is empty
if (global.JSUtil.nil(row[currentHeader])) {
isValid = false;
 

}
}
}

return isValid;

},

type: 'validateheaders'
});
 Thank you in advance!
2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@ujjwala_678 You are using 

g_form.getControl('oi_order_now_button').click(); 

g_form.getControl method is not supported on the Service Portal.

 

Screenshot 2023-12-03 at 10.47.15 PM.png

Reference: https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideFormAPI#r_GlideFormGetCon...

 

Since this method is not supported, hence you are seeing the javascript error in the console.

Hope this helps.

Hello,

Thank you for your inputs on this.....Could you suggest me any other method which i can use in my code so that client script will not throw any error even on sp?

Thank you!