
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2017 12:12 PM
We've upgraded to Istanbul and are beginning the process of deploying scripted REST APIs for external integrations. At the same time we'd like to leverage the same calls from certain client scripts but I'm unable to find any information about how this might be done. Any help?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 07:21 AM
williambusby here are code examples from my getReferenceAdvanced solution. Setup your scripted rest to provide a JSON string response, I find that easier to deal with especially with multiple values.
Establish an object (key and value pair) and put data into it:
var answerList = {};
answerList.key = value;
Then at the very end of your script encode this object into a JSON string to pass back to the client script:
var answer = new JSON().encode(answerList);
return answer.toString();
Once that is setup then here is an example client script that calls the "getreferenceadvanced" scripted REST. Notice that it parses the JSON string to create an object that you can then leverage in your code like setValue() functions. As noted in the comments you can also pass the session token for authentication so you don't have to pass in credentials for your REST service.
var fieldValue = g_form.getValue(fieldName);
//Call the getreferenceadvanced scripted REST web service to get the data requested
var restEndPoint = "api/snc/getreferenceadvanced/";
restEndPoint = restEndPoint + fieldValue;
var serverRequest = new XMLHttpRequest();
serverRequest.open("get", restEndPoint, false);
//The getreferenceadvanced scripted REST web service requires authentication so pass user session token
serverRequest.setRequestHeader("X-UserToken", g_ck);
serverRequest.setRequestHeader("Accept", "application/json");
serverRequest.setRequestHeader("Content-Type", "application/json");
serverRequest.send();
if (serverRequest.status === 200) {
var serverResponse = JSON.parse(serverRequest.response);
var refResponse = JSON.parse(serverResponse.result);
g_form.setValue("FIELD-NAME", refResponse.key);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 03:01 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"
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:35 AM
SysID's are unique across the instance so you aren't going to find multiple records with the same ID. You will need to create a script that searches across the various tables by that SysID and its really unrelated to the original question in this post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 07:54 AM
Michael, thanks for the correction!
-Rob