Scenario
A Suitelet is called by a Workflow Action Script, using nlapiRequestURL. After calling the Suitelet, the response value is stored in a JSON Object. The error: "Unexpected Token <" is then shown.
Interpreting the error: the "Unexpected Token <" error is usually encountered when you're including or posting to a file/URL which doesn't exist or is not accessible. The server will return a regular html-formatted error page e.g. "404 Not Found" enclosed with <html></html> tags.
The html-formatted error page's source file is what is then received as the response and stored into a JSON object. And since that first chevron < isn't a valid js nor valid json, it triggers the unexpected token.
Solution
SuiteScript 1.0:
varresponse=nlapiRequestURL(url,null,a)//nlapiRequestURL with authorizationvarrespoValue=response.getBody();//Get the response value using .getBody() methodnlapiLogExecution("DEBUG","Response Value",respoValue);//Log
SuiteScript 2.0:
varresponse=http.request({method:http.Method.GET,url:url,headers:a})varrespoValue=response.boyd log.debug('Response Value',respoValue)
2. Check the response value1. Go to Customization > Scripting > Scripts
2. Look for the script and click on View
3. On the script record, go to Execution Log subtab
4. Find the line that has the title Response Value
5. Click View
3. Copy the HTML source file and go to w3schools Tryit to invoke the web page and better understand the problem. From here, verify how the issue can be further resolved based on the following:
1.Your Session has Timed Out page: Admin account is used to access the Suitelet, use a less privileged account.
2.Please Login page : The role used in the authorization header does not have enough permission to access the Suitelet