-
Notifications
You must be signed in to change notification settings - Fork 51
/
RestCallRemote.js
118 lines (91 loc) · 2.76 KB
/
RestCallRemote.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var r = new sn_ws.RESTMessageV2('Hana', 'get');
var response = r.execute();
var responseBody = response.getBody();
var parsed = JSON.parse(responseBody);
var el = parsed.d.EntitySets.length;
//gs.print(parsed.d.EntitySets[0]);
gs.print(el);
var r = new sn_ws.RESTMessageV2('Hana', 'get');
var response = r.execute();
var responseBody = response.getBody();
var parsed = JSON.parse(responseBody);
var prnr = parsed.d.results.Objid;
gs.print(prnr);
//var el = parsed.d.EntitySets.length;
//gs.print(parsed.d.EntitySets[0]);
//var es = parsed.d.EntitySets;
//gs.print(el);
// for (var i=0; i<el; i++) {
// gs.print(es[i]);
// }
=====================
var r = new sn_ws.RESTMessageV2('Hana', 'get');
var response = r.execute();
var responseBody = response.getBody();
var parsed = JSON.parse(responseBody);
var prnr = parsed.d.results[0].Objid;
var res = parsed.d.results;
var el = parsed.d.EntitySets.length;
gs.print(res.length);
for (var i=0; i<res.length; i++) {
gs.print(res[i].Objid);
}
var r = new sn_ws.RESTMessageV2('Hana', 'get');
var response = r.execute();
var responseBody = response.getBody();
var parsed = JSON.parse(responseBody);
var obj = parsed.d.results;
var arr = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
arr.push(key + '=' + obj[key]);
}
};
var result = arr.join(',');
gs.print(obj);
======
var r = new sn_ws.RESTMessageV2('HRWF', 'get');
r.setAuthentication('basic', 'oData Service Account');
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
var httpStatus = response.getStatusCode();
var oResponse = responseBody.d;
for (var key in oResponse) {
if (oResponse.hasOwnProperty(key)) {
gs.print(key + " -> " + oResponse[key]);
}
}
+++++
Object.keys(oResponse).forEach(function(key) {
gs.print(key + " -> " + oResponse[key]);
});
======
try {
var r = new sn_ws.RESTMessageV2('Connect@Plant', 'get');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthentication(authentication type, profile name);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.getMessage();
}
var parser = new JSONParser();
var parsedResponse = parser.parse(responseBody);
for (var i = 0 ; i < parsedResponse.length; i++) {
var myObject = parsedResponse[i];
var title = parsedResponse[i].title;
var type = parsedResponse[i].type;
var description = parsedResponse[i].description;
var appGroup = parsedResponse[i].appGroup;
var gr = new GlideRecord('u_imp_connectatplant');
gr.initialize();
gr.u_description = description;
gr.u_name = title;
gr.u_type = type;
gr.u_appgroup = appGroup;
gr.sys_import_set = '9c75f6030ff776003867715ce1050ee0';
gr.insert();
}