Unexpected token: < error thrown from ServiceNow

Tejal Zete1
Tera Contributor

In the below workflow screenshot error(Unexpected token: < ) is getting added in CATALOG task

 

TejalZete1_0-1667807199864.png

 

code written in Run script  :- 

var User = current.variables.common_vars_requested_for.user_name; // User ID
var Domain = current.variables.var_select_domain; // Selected Domain
var Groups = current.variables.var_select_group.getDisplayValue(); // Selected Group

var I =new CAH_IIQ_AD_Groups().SendDataToIIQ(User,Domain,Groups,"");

if (I[0] == "Success"){
workflow.scratchpad.WebService = "Success";
workflow.scratchpad.SamAccount = I[1];workflow.scratchpad.RequestID = I[2];
current.work_notes = "SAM Account Name - " + workflow.scratchpad.SamAccount + " - Request ID - " + workflow.scratchpad.RequestID;
}
else{
workflow.scratchpad.error = I;
workflow.scratchpad.WebService = "Failure";
}

 

CAH_IIQ_AD_Groups Script include method SendDataToIIQ code:-

SendDataToIIQ: function(User, Domain, Group) {
var errMsg = '';
try {
this.UserID = User;
this.Domain = Domain;
this.Groups = Group;
var r;
if (this.Domain == "Dev.npch.int") {
r = new sn_ws.RESTMessageV2('IIQ-AD-Dev', 'Default Post');
}
if (this.Domain == "Stg.cardinalhealth.net") {
r = new sn_ws.RESTMessageV2('IIQ-AD-Stage', 'Default Post');
}
if (this.Domain == "Appzone.dmz" || this.Domain == "Cardinalhealth.net") {
r = new sn_ws.RESTMessageV2('IIQ-AD-Prod', 'Default Post');
}
var requestBody = '';
requestBody = this.generateJSONPayload(); // To Get Requuest ID and SAM Account
r.setRequestBody(requestBody);
gs.log("SendDataToIIQ - Request Body - " + requestBody, "Cat Item:Access Request for AD Groups");
var response = r.execute();
var responseBody = response.getBody();
gs.log("SendDataToIIQ - Response Body - " + responseBody, "Cat Item:Access Request for AD Groups");
var httpStatus = response.getStatusCode();
var myObj = JSON.parse(responseBody);

if (httpStatus != 200 || myObj.errors != null || myObj.fault != null || myObj.attributes.ValidationErrors != null) {
errMsg = 'HTTP Status: ' + httpStatus;

if (myObj.errors) {
errMsg += ', Errors: ' + myObj.errors + '\nRequest: ' + requestBody;
}
if (myObj.fault) {
errMsg += ', Fault: ' + myObj.fault.detail.errorcode + '\nRequest: ' + requestBody;
}
if (myObj.attributes.ValidationErrors) {
errMsg += ', Validation Error: ' + myObj.attributes.ValidationErrors + '\nRequest: ' + requestBody;
}
return errMsg;
} else {
return ["Success", myObj.attributes.sAMAccountName, myObj.requestID];
}
} catch (ex) {
errMsg = ex.message + '\nRequest: ' + requestBody;
return errMsg;
}
},

 

If box code from workflow :- 

answer = ifScript();

function ifScript() {
if (workflow.scratchpad.WebService == "Success") { // Got Success from IIQ web Service Call
return 'yes';
}
return 'no';
}

 

catalog task code where error is getting in :-

// Set values for the task in this script. Use the variable 'task' when setting additional values.
// Note: This script is run after the task values are set using the Fields, Template or Values you have specified.
//
// For example:
// task.short_description = current.short_description;
task.description = workflow.scratchpad.error;

 

 

Please suggest on this as I am new in REST 

 

 

 

 

0 REPLIES 0