JST-310001 Error while evaluating a JavaScript code, line 1: (void 0) is not a function. | Community
Skip to main content
wankang
Level 3
April 6, 2023
Solved

JST-310001 Error while evaluating a JavaScript code, line 1: (void 0) is not a function.

  • April 6, 2023
  • 2 replies
  • 3441 views
when use postman via soap, it shows JST-310001 Error while evaluating a JavaScript code, line 1: (void 0) is not a function. here is my js code, is there any style error. function cus_smsApiService_SendSingleSms(userid,pwd,mobile,content,timestamp){ var USER_ID = userid; var PWD = pwd; var MOBILE = mobile; var CONTENT = content; var TIMESTAMP = timestamp; var API = 'http://112.91.147.37:9003/sms/v2/std/send_single'; var PARAMETERS= "userid="+USER_ID+"pwd="+PWD+"mobile="+MOBILE+"content="+CONTENT+"timestamp="+TIMESTAMP; var URL = API+"?"+PARAMETERS; var http = new HttpClientRequest(URL); http.method="GET"; http.execute(); var r = http.response; var responseJSON = JSON.parse(r.body); logInfo("JSON"+responseJSON); }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by david--garcia

I've replicated your solution and I got past the issue, the problem seems in the naming convention somewhere or in the SOAP call not including the correct headers SOAPaction headers, for testing I've named my assets as following

Schema: cus:smsApiService --> uppercase S for Service

         JS: cus:smsApiService.js

 Method: SendSingleSms

 

Payload

 

POST /nl/jsp/soaprouter.jsp HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 SOAPAction: cus:smsApiService#SendSingleSms Content-Length: 303 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <SendSingleSms xmlns="urn:cus:SendSingleSms"> <sessiontoken>david/12345</sessiontoken> <userid>12345</userid> </SendSingleSms> </soap:Body> </soap:Envelope>

 

 

Make sure your are naming your function correctly

 

And firstly test it with just a simple string from your payload rather than a full request

 

SOAP request should be as follows

 

And it should include the SOAPAction header with value cus:smsApiService#SendSingleSms

Also check uppercase/lowercase in your schema/js code/function names, make sure it has the correct case.

 

 

 

 

 

2 replies

Marcel_Szimonisz
Community Advisor
Community Advisor
April 6, 2023

Hello @wankang ,

it looks like syntax error but i do not see any 🙂

have you set all correctly?

  • js library
  • cus:smsApiService schema methods and in arguments?
... <methods> <method library="cus:smsApiServiceLibrary" name="SendSingleSMS" static="true"> <!-- in out arguments--> ...

 

Maybe if the library is just created restart the server?

Marcel

wankang
wankangAuthor
Level 3
April 6, 2023

yes, i had set 

  • js library
  • cus:smsApiService schema methods and in arguments

also i just restart, but still had same issue.plz find the below data.

 

 

the data schema:

<srcSchema _cs="smsApiservice (cus)" created="2023-04-06 03:05:06.758Z" createdBy-id="0"
entitySchema="xtk:srcSchema" img="xtk:schema.png" label="smsApiservice"
lastModified="2023-04-06 07:09:59.317Z" mappingType="sql" md5="A7508FE33755B438FE5ADAD16C08D522"
modifiedBy-id="0" name="smsApiservice" namespace="cus" xtkschema="xtk:srcSchema">

<element autopk="true" label="smsApiservice" name="smsApiservice">
<attribute label="User account" name="userid" type="string"/>
<attribute label="User Password" name="pwd" type="string"/>
<attribute label="Mobile phone number for SMS reception" name="mobile" type="string"/>
<attribute label="SMS content" name="content" type="string"/>
<attribute label="time stamp" name="timestamp" type="string"/>
</element>

<methods>
<method library="cus:smsApiService.js" name="SendSingleSms" static="true">
<parameters>
<param desc="User account" inout="in" name="userid" type="string"/>
<param desc="User Password" inout="in" name="pwd" type="string"/>
<param desc="Mobile phone number for SMS reception" inout="in" name="mobile"
type="string"/>
<param desc="SMS content" inout="in" name="content" type="string"/>
<param desc="time stamp" name="timestamp" type="string"/>
<param desc="Business type" name="svrtype" type="string"/>
<param desc="Extension number" name="exno" type="string"/>
<param desc="User defined serial number" name="custid" type="string"/>
<param desc="Custom Extended Data" name="exdata" type="string"/>
<param desc="res" name="result" inout="out" type="int"/>
<param desc="desc" name="desc" inout="out" type="int"/>
</parameters>
</method>
</methods>
</srcSchema>

 

the js code:

 

function SendSingleSms(userid,pwd,mobile,content,timestamp,svrtype,exno,custid,exdata){
var USER_ID = userid;
var PWD = pwd;
var MOBILE = mobile;
var CONTENT = content;
var TIMESTAMP = timestamp;
var API = 'http://112.91.147.37:9003/sms/v2/std/send_single';
var PARAMETERS= "userid="+USER_ID+"pwd="+PWD+"mobile="+MOBILE+"content="+CONTENT+"timestamp="+TIMESTAMP;
var URL = API+"?"+PARAMETERS;

var http = new HttpClientRequest(URL);
http.method="GET";
http.execute();
var r = http.response;
var responseJSON = JSON.parse(r.body);
logInfo("JSON"+responseJSON);
}

 

 

Marcel_Szimonisz
Community Advisor
Community Advisor
April 6, 2023

Hello @wankang ,

you are missing bunch of inout="in" for some parameters.

Also the function is not returning anything, and i have no idea how to handle multiple out variables in your case.

 

I usually return dom document with all variables mapped to it.

Marcel

david--garcia
david--garciaAccepted solution
Level 10
April 6, 2023

I've replicated your solution and I got past the issue, the problem seems in the naming convention somewhere or in the SOAP call not including the correct headers SOAPaction headers, for testing I've named my assets as following

Schema: cus:smsApiService --> uppercase S for Service

         JS: cus:smsApiService.js

 Method: SendSingleSms

 

Payload

 

POST /nl/jsp/soaprouter.jsp HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 SOAPAction: cus:smsApiService#SendSingleSms Content-Length: 303 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <SendSingleSms xmlns="urn:cus:SendSingleSms"> <sessiontoken>david/12345</sessiontoken> <userid>12345</userid> </SendSingleSms> </soap:Body> </soap:Envelope>

 

 

Make sure your are naming your function correctly

 

And firstly test it with just a simple string from your payload rather than a full request

 

SOAP request should be as follows

 

And it should include the SOAPAction header with value cus:smsApiService#SendSingleSms

Also check uppercase/lowercase in your schema/js code/function names, make sure it has the correct case.

 

 

 

 

 

RajeshBhat
Level 3
February 27, 2024

Hi @david--garcia ,

I followed your response and made changes to resolve the javascript error. But still keep getting the same error: "Error while evaluating a javascript code, line 1: void(0) is not a function". I'm attaching the complete details of the changes I have done on input form, schema and new js code file. Please let me know how to resolve this issue. Many thanks in advance!