- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 12:51 AM
Hi
I am calling GET method and fetching below response.
[{
"expand": "description,lead,issueTypes,url,projectKeys,permissions,insight",
"self": "https://.atlassian.net/rest/api/3/project/10013",
"id": "10013",
"key": "ACQINT",
"name": "Acquisition Integrations",
"avatarUrls": {
"48x48": "https://.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10412",
"24x24": "https://.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10412?size=small",
"16x16": "https://.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10412?size=xsmall",
"32x32": "https://.atlassian.net/rest/api/3/universal_avatar/view/type/project/avatar/10412?size=medium"
},
"projectTypeKey": "software",
"simplified": false,
"style": "classic",
"isPrivate": false,
"properties": {}
}, {
"expand": "descrip
I want to show id, key and name three fields from above response.
Pls. find my code below
var r = new sn_ws.RESTMessageV2('JiraIntegrationEndpoint', 'Get Issue Details');
r.setEndpoint("https://.atlassian.net/rest/api/3/project");
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
var httpStatus = response.getStatusCode();
gs.print("responseBody Project:" + responseBody);
gs.print("httpStatus Project:" + httpStatus);
var ot = JSON.stringify(responseBody);
gs.print("responseBody Project ID:" + ot);
var name= [];
var id = [];
var key = [];
for (var i = 0; i < ot.length; i++) {
name.push('' + ot[i].name);
id.push('' + ot[i].id);
key.push('' + ot[i].key);
}
if (httpStatus == '200') {
if (responseBody.length != 0) {
gs.print("responseBody inside if Projects:" + ot);
}
}
Could you please help me in this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 04:29 AM
Hi,
update as this
var r = new sn_ws.RESTMessageV2('JiraIntegrationEndpoint', 'Get Issue Details');
r.setEndpoint("https://.atlassian.net/rest/api/3/project");
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
var httpStatus = response.getStatusCode();
var ot = JSON.parse(responseBody);
for (var i = 0; i < ot.length; i++) {
var name = ot[i].name;
var id = ot[i].id;
var key = ot[i].key;
var gr = new GlideRecord("u_jira_projects");
gr.initialize();
gr.u_name = name;
gr.u_id = id;
gr.u_key = key;
gr.insert();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 12:59 AM
Hi
instead of
var ot = JSON.stringify(responseBody);
please use
var ot = responseBody;
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 01:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 01:26 AM
Hi
this is exactly you can expect if printing the ot object, because it is an object and not text!
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 02:37 AM
I got this.
thank you Maik.