SyntaxError: Unexpected token: E (sys_script_include.d2426c9ec0a8016501958bf2ac79c775.script; line 155
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2021 02:23 AM
Hi,
I am getting "SyntaxError: Unexpected token: E (sys_script_include.d2426c9ec0a8016501958bf2ac79c775.script; line 155" error in workflow for few tickets,Is there any issue with my script?
var tok = '';
var resp = '';
var stat;
var when = new GlideDateTime();
var delay = new GlideTime();
delay.setValue("00:00:02");
when.add(delay);
var smm = new sn_ws.RESTMessageV2('SAVE Token', 'Save Tok');
smm.setHttpTimeout(120000);
respon = smm.execute();
stat = respon.getStatusCode();
gs.log('token status' + stat);
if (stat == 200) {
//resp = respon.haveError() ? respon.getErrorMessage() : respon.getBody();
var requestBody1 = smm.getRequestBody();
gs.log('Request Body for Request Creation::: ' + requestBody1);
resp = respon.getBody();
gs.log("respon for request Creation:::" + resp);
tok = JSON.parse(resp).access_token;
gs.log(tok);
gs.log("token for request creation::::" + tok);
var requestBody;
var responseBody;
var status;
var r;
var res;
var ret;
var role;
var smtp = "SMTP:";
var email = current.variables.please_enter_external_email_address;
var proxyaddresses;
if (current.variables.ext_user == 'contractor_no_mail') {
proxyaddresses = smtp + email;
} else {
proxyaddresses = '';
}
gs.log("check the smtp" + proxyaddresses);
var lis_type = current.variables.license_type;
if (lis_type == 'internal_user_mobile') {
role = current.variables.internal_user_mobile.getDisplayValue();
} else if (lis_type == 'internal_user_stationary') {
role = current.variables.internal_user_stationary.getDisplayValue();
} else if (lis_type == 'ext_user') {
role = current.variables.ext_user.getDisplayValue();
} else if (lis_type == 'other_account') {
role = current.variables.other_account.getDisplayValue();
}
try {
r = new sn_ws.RESTMessageV2('New AD Account', 'post');
r.setStringParameter("token", tok);
r.setHttpTimeout(120000); //In milliseconds. Wait at most 10 seconds for response from http request.
r.setStringParameterNoEscape('Employee Number', current.variables.ccba_employee_number);
r.setStringParameterNoEscape('Title', current.variables.ccba_job_title);
r.setStringParameterNoEscape('First Name', current.variables.ccba_first_name);
r.setHttpTimeout(120000);
response = r.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
} catch (ex) {
responseBody = ex.getMessage();
status = '500';
} finally {
requestBody = r ? r.getRequestBody() : null;
}
res = response.getBody();
ret = JSON.parse(res).RequestId;
gs.log(ret);
gs.log("passing the ticket number::::" + ret);
current.u_vendor_ticket_number = ret;
gs.info("Request Body for New AD: " + current.number + requestBody);
gs.info("Response for for New AD " + current.number + responseBody);
gs.info("HTTP Status for New AD" + current.number + status);
if (status == 200) {
//if(responseBody.indexOf('success')>-1){
activity.result = 'success';
} else {
activity.result = 'Method failed';
current.work_notes = "New AD user account" + ' ' + current.number + ' ' + 'has been cancelled.' + "Reason: The user already exists / the employee number provided is incorrect.";
}
}
else{
activity.result = 'rollback';
}
Thank You,
Arkesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2021 02:31 AM
Hi
which line is the one with the number 155? The above code only has 91 lines 😞
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2021 02:34 AM
Hi Maik,
error says, issue is with script include "JSON" which is a OOB.
I found this community answer but dont know what is the issue
https://community.servicenow.com/community?id=community_question&sys_id=462854d2dbb0d340b61ff3231f961935
Thank you,
Arkesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2021 02:37 AM
Script Include: JSON
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2021 02:42 AM
This error usually means that there have been a problem with parsing your JSON (the "u" usually means "undefined" for the variable you try to access).
A first culprit to maybe look at would be the line:
tok = JSON.parse(resp).access_token;
I would check if "resp" really is a JSON at this point, and if so, if it contains a property called "access_token".