Expand my Community achievements bar.

SOLVED

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

Avatar

Level 3
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); }
1 Accepted Solution

Avatar

Correct answer by
Level 10

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>

 

David__Garcia_0-1680784640961.png

 

Make sure your are naming your function correctly

David__Garcia_1-1680784811515.png

 

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

David__Garcia_2-1680784966432.png

 

SOAP request should be as follows

David__Garcia_3-1680785164891.png

 

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.

 

 

 

 

 

View solution in original post

10 Replies

Avatar

Community Advisor

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

Avatar

Level 3

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);
}

 

 

Avatar

Community Advisor

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

Avatar

Level 3

 

after i Complete all inout="in", restart, the problem still happen.plz find below 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 08:59:19.076Z" mappingType="sql" md5="C51540F6404352389040E82C9DE14174"
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" inout="in" name="timestamp" type="string"/>
<param desc="Business type" inout="in" name="svrtype" type="string"/>
<param desc="Extension number" inout="in" name="exno" type="string"/>
<param desc="User defined serial number" inout="in" name="custid" type="string"/>
<param desc="Custom Extended Data" inout="in" name="exdata" type="string"/>
<param desc="res" inout="out" name="result" type="int"/>
<param desc="desc" inout="out" name="desc" type="string"/>
</parameters>
</method>
</methods>
</srcSchema>

Avatar

Level 3

could u give a js example, i would like to see how to reutrn dom document

Avatar

Level 3

this can be call, i just add "cus_smsApiservice_" before name

 

function cus_smsApiservice_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();
return "success";
}

Avatar

Level 3

by the way, i only create js file cus:smsApiService.js, and data schema, then restart, and SOAP url should generate, and i use generated wsdl to call, and then line 1: (void 0) is not a function happend.

 

what  you said set js library is just Configure in data schema?

Avatar

Community Advisor

i mean if that function is saved under the  administration --> ....--> Javascript codes exactly as you have in your schema.

Avatar

Correct answer by
Level 10

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>

 

David__Garcia_0-1680784640961.png

 

Make sure your are naming your function correctly

David__Garcia_1-1680784811515.png

 

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

David__Garcia_2-1680784966432.png

 

SOAP request should be as follows

David__Garcia_3-1680785164891.png

 

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.

 

 

 

 

 

Avatar

Level 2

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!JSError.jpg