- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 04:32 AM
Hi,
I developed scripted rest API on one instance, tested, and it worked. After Export to XML and upload to different developer instance I got an error:
{
"error": {
"detail": "TypeError: undefined is not a function. (sys_ws_operation.81ccc7210feb2200d1be489ce1050e41; line 4)",
"message": "undefined is not a function."
},
"status": "failure"
}
My rest api:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var JSONG = new global.JSONG();
var testName = request.body.data.name;
var gr = new GlideRecord("sysauto_script");
gr.get("name", testName);
var execute = new global.ExecuteScheduledJob();
execute.executeNow(gr);
sleep(10000);
function sleep(ms) {
var unixtime_ms = new Date().getTime();
while(new Date().getTime() < unixtime_ms + ms) {}
}
var testResult;
var result = new GlideRecord("u_unit_test_result");
result.orderByDesc("sys_created_on");
result.query();
var resultArr = [];
if(result.next()){
resultArr.push(JSONG.encodeGr(result));
}
response.setBody(resultArr);
return;
})(request, response);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
What could be wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 06:42 AM
Ok, these two functions were defined globally. Moved them in REST API code, it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 04:48 AM
What is JSONG() in "var JSONG = new global.JSONG();" ? Shouldn't it be JSON?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 05:13 AM
Seems a little bit better, now it fails on
org.mozilla.javascript.EcmaError: undefined is not a function.
Caused by error in sys_ws_operation.81ccc7210feb2200d1be489ce1050e41 at line 9
6: var gr = new GlideRecord("sysauto_script");
7: gr.get("name", testName);
8:
==> 9: var execute = new global.ExecuteScheduledJob();
10: execute.executeNow(gr);
11:
12: sleep(10000);
But it was working fine as
var JSONG = new global.JSONG();
on instance I developed this Rest API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2016 06:42 AM
Ok, these two functions were defined globally. Moved them in REST API code, it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 03:02 PM
Hello,
I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.
Could you please guide me how to implement this? Sample code would be great.
Input: Sys ID of the record
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"sys_id": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"sys_id": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}