-
Notifications
You must be signed in to change notification settings - Fork 5
/
saprfc.html
473 lines (395 loc) · 17 KB
/
saprfc.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<script type="text/x-red" data-template-name="saprfc-config">
<div class="form-row">
<label for="node-config-input-nickname"><i class="icon-bookmark"></i> Nickname</label>
<input type="text" id="node-config-input-nickname" placeholder="Prod" />
</div>
<div class="form-row">
<label for="node-config-input-host"><i class="icon-bookmark"></i> Host</label>
<input type="text" id="node-config-input-host" placeholder="sapr3.mycompany.com" />
</div>
<div class="form-row">
<label for="node-config-input-client"><i class="fa fa-bookmark"></i> Client</label>
<input type="text" id="node-config-input-client" placeholder="100" style="width: 20%" />
</div>
<div class="form-row">
<label for="node-config-input-systemNumber"><i class="fa fa-bookmark"></i> System Number</label>
<input class="input-append-left" type="text" id="node-config-input-systemNumber" placeholder="15" style="width: 20%" />
</div>
<div class="form-row">
<label for="node-config-input-sapRouter"><i class="fa fa-bookmark"></i> Router (optional)</label>
<input class="input-append-left" type="text" id="node-config-input-sapRouter" />
</div>
<div class="form-row">
<label for="node-config-input-username"><i class="fa fa-bookmark"></i> Username</label>
<input class="input-append-left" type="text" id="node-config-input-username" />
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-bookmark"></i> Password</label>
<input class="input-append-left" type="password" id="node-config-input-password">
</div>
<div class="form-row">
<label for="node-config-input-lang"><i class="fa fa-bookmark"></i> Language</label>
<input class="input-append-left" type="text" id="node-config-input-lang" placeholder="EN" style="width: 20%" />
</div>
<div class="form-tips">
All settings are for the remote SAP System where Remote Function Calls would be made. These settings should match your SAP GUI connection settings.
<ul>
<li>Nickname: A friendly name for the system. (Dev/Test/Prod/etc)</li>
<li>Host: The IP or hostname.</li>
<li>Client: The client ID of the remote SAP System.</li>
<li>System Number: Also known as "Instance Number"</li>
<li>Username: make sure this user has authorization for the RFCs that will be called</li>
<li>Language: Two digit ISO code of the logon language</li>
</ul>
</div>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('saprfc-config',{
category: 'config',
defaults: {
nickname: {value:"Prod",required:true},
},
credentials: {
nickname: {type: "text"},
host: {type: "text", required: true},
client: {type: "text", required: true},
systemNumber: {type: "text", required: true},
sapRouter: {type: "text"},
username: {type: "text", required: true},
password: {type: "password", required: true},
lang: {type: "text", required: true}
},
label: function() {
return this.nickname;
},
oneditprepare: function() {
},
exportable: false
});
})();
</script>
<script type="text/x-red" data-template-name="call">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-system"><i class="icon-tag"></i> System</label>
<input type="text" id="node-input-system">
</div>
<div class="form-row">
<label for="node-input-remoteFunction"><i class="icon-tag"></i> Function To Call</label>
<input type="text" id="node-input-remoteFunction" placeholder="Enter RFC Name">
</div>
<div class="form-tips">
<p>The input payload will be passed to the RFC - use a function node to build an object matching the RFC's specific requirements.</p>
<p>Example input payload to update a user email with <em>BAPI_USER_CHANGE</em>:
<pre>{
USERNAME: "SOME-USERNAME",
ADDRESS: {
E_MAIL: "user@company.com"
},
ADDRESSX: {
E_MAIL: "X"
}
}</pre>
</p>
<p>The output payload contains the data returned by the RFC.</p>
<p>Use a <strong>Catch</strong> node to catch and process any errors encountered by the RFC.</p>
</div>
</script>
<script type="text/x-red" data-help-name="call">
<p>Make an SAP Remote Function Call</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('call',{
category: 'sapRFC',
color: '#4091ed',
defaults: {
name: {value:""},
system: {type:"saprfc-config", required: true},
remoteFunction: {value:"", required: true}
},
inputs:1,
outputs:1,
icon: "function.png",
label: function() {
return this.name||this.remoteFunction||"call";
}
});
</script>
<script type="text/x-red" data-template-name="read table">
<div class="form-row">
<div id="node-message"></div>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-system"><i class="icon-tag"></i> System</label>
<input type="text" id="node-input-system">
</div>
<div class="form-row">
<label for="node-input-table"><i class="icon-tag"></i>Table</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 70px">
<input type="text" id="node-input-table" placeholder="MARA">
</div>
<a class="btn" id="node-input-table-fetch-fields" style="position: absolute; right: 0px; top: 0px;">Fetch Fields</a>
</div>
</div>
<div class="form-row node-input-target-row">
<div id="node-input-status-target-container-div" style="min-height: 100px; position: relative; box-sizing: border-box; border-radius: 2px; height: 180px; border: 1px solid #ccc;overflow:hidden; ">
<div style="box-sizing: border-box; line-height: 20px; font-size: 0.8em; border-bottom: 1px solid #ddd; height: 20px;">
<input type="checkbox" title="select all" id="node-input-target-field-checkbox-all" style="width: 30px; margin: 0 2px 1px 2px;">
<div style="display: inline-block;"><a id="node-input-target-sort-label" href="#" title="sort"><span>field</span> <i class="node-input-status-sort-label-a fa fa-caret-down"></i><i class="node-input-status-sort-label-d fa fa-caret-up"></i></a></div>
<div style="position: absolute; right: 10px; width: 50px; display: inline-block; text-align: right;"><a id="node-input-target-sort-id" href="#" title="sort"><span title="id">id</span><i class="node-input-status-sort-id-a fa fa-caret-down"></i><i class="node-input-status-sort-id-d fa fa-caret-up"></i></a></div>
</div>
<div style="background: #fbfbfb; box-sizing: border-box; position:absolute; top:20px;bottom:0;left:0px;right:0px; overflow-y: scroll; overflow-x: hidden;">
<ul id="node-input-status-target-container" style=" list-style-type:none; margin: 0;"></ul>
</div>
</div>
</div>
<div class="form-tips">
<p>You can use a function node to pass parameters to RFC_READ_TABLE. Sample payload:
<pre>msg.payload = {
OPTIONS: ["MATNR EQ 'SOME_MATERIAL_NUMBER'"],
ROWCOUNT: 10
}</pre>
</p>
<p>Valid payload properties are: <em>TABLE, FIELDS, OPTIONS, ROWCOUNT, ROWSKIP</em>. TABLE & FIELDS be set in the node's configuration instead of the payload.</p>
<p>The output payload contains the parsed data returned by RFC_READ_TABLE.</p>
<p>Use a <strong>Catch</strong> node to catch and process any errors encountered by the RFC.</p>
</div>
<style>
#node-input-status-target-container {
position: relative;
}
#node-input-status-target-container li {
padding: 2px 5px;
background: none;
font-size: 0.8em;
margin:0;
white-space: nowrap;
}
#node-input-status-target-container li label {
margin-bottom: 0;
width: 100%;
}
#node-input-status-target-container li label input {
vertical-align: top;
width:15px;
margin-right: 10px;
}
#node-input-status-target-container li:hover,
#node-input-status-target-container li:hover .node-input-target-field-label {
background: #f0f0f0;
}
.node-input-target-field-id {
position:absolute;
right: 0px;
padding-right: 10px;
padding-left: 10px;
font-size: 0.8em;
background: #fbfbfb;
}
</style>
</script>
<script type="text/x-red" data-help-name="read table">
<p>Read data from an SAP Table</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('read table',{
category: 'sapRFC',
color: '#4091ed',
defaults: {
name: {value:"read table"},
system: {type:"saprfc-config", required: true},
table: {value:"", required: true},
selectedFields: {value:null}
},
inputs:1,
outputs:1,
icon: "db.png",
label: function() {
return this.name||"read "+this.table;
},
oneditprepare: function() {
var node = this;
var nodeId = this.id;
var fieldListContainer = $("#node-input-status-target-container");
function createFieldList() {
var selectedFields = node.selectedFields || [];
fieldListContainer.empty();
$("#node-message").html("");
var data = {
nodeId: nodeId,
table: $("#node-input-table").val(),
systemConfig: $("#node-input-system").val()
}
if($("#node-input-system").val() === "_ADD_"){
$("#node-message").html("<span style=\"color: red\">Please select a system</span>");
return;
}
// Load the field list for the specified table from the server
$.ajax({
method: "post",
dataType: "json",
url: 'saprfc_table_fields',
data: data,
success: function(data){
$("#node-input-table").removeClass("input-error");
if(data.error){
$("#node-message").html("<span style=\"color: red\">"+data.message+"</span>");
// This is not conventional, but we need a way to output the sapError object to the debug window in case the RFC fails
// node.error() is not in context here
RED.debug.handleDebugMessage({name:"error: read table",msg:data.sapError, level: 20});
// console.log(data.sapError);
$("#node-input-table").addClass("input-error");
return;
}
data.fieldList.forEach((field) => {
var isChecked = selectedFields.indexOf(field.id) !== -1;
var container = $('<li/>',{class:"node-input-target-field"});
var row = $('<label/>',{for:"node-input-target-field-"+field.id}).appendTo(container);
$('<input>',{type:"checkbox",class:"node-input-target-field-checkbox",id:"node-input-target-field-"+field.id})
.data('field-id',field.id)
.prop('checked', isChecked)
.appendTo(row);
container.on('mouseover',function(e) {
field.highlighted = true;
});
container.on('mouseout',function(e) {
field.highlighted = false;
});
$('<span>',{class:"node-input-target-field-label",style:"white-space:nowrap"}).text(field.label).appendTo(row);
$('<span>',{class:"node-input-target-field-id"}).text(field.id).appendTo(row);
container.appendTo(fieldListContainer);
});
$(".node-input-target-field-checkbox").change(function() {
if (!this.checked) {
$("#node-input-target-field-checkbox-all").prop('checked',false);
}
});
},
error: function(err){
// This is not conventional, but we need a way to output the sapError object to the debug window in case the ajax call fails
// node.error() is not in context here
RED.debug.handleDebugMessage({name:"error: read table",msg:err, level: 20});
// console.log("Error: ",err);
}
}); // ajax
} // createFieldList
function sortfieldListContainer(sortOn) {
var currentSort = fieldListContainer.data('currentSort');
var currentSortOrder = fieldListContainer.data('currentSortOrder');
if (!currentSort) {
currentSort = sortOn;
currentSortOrder = 'a';
} else {
if (currentSort === sortOn) {
currentSortOrder = (currentSortOrder === 'a'?'d':'a');
} else {
currentSortOrder = 'a';
}
currentSort = sortOn;
}
fieldListContainer.data('currentSort',currentSort);
fieldListContainer.data('currentSortOrder',currentSortOrder);
$("#node-input-status-target-container-div .fa").hide();
$(".node-input-status-sort-"+currentSort+"-"+currentSortOrder).show();
var items = fieldListContainer.find("li").get();
items.sort(function(a,b) {
var labelA = $(a).find(".node-input-target-field-"+currentSort).text().toLowerCase();
var labelB = $(b).find(".node-input-target-field-"+currentSort).text().toLowerCase();
if (labelA < labelB) { return currentSortOrder==='a'?-1:1; }
if (labelA > labelB) { return currentSortOrder==='a'?1:-1; }
return 0;
});
$.each(items, function(i, li) {
fieldListContainer.append(li);
});
}// sortfieldListContainer
$("#node-input-target-sort-id").click(function(e) {
e.preventDefault();
sortfieldListContainer('id');
});
$("#node-input-target-sort-label").click(function(e) {
e.preventDefault();
sortfieldListContainer('label');
});
// pre populate the field list if the table name already is set
if($("#node-input-system").val() !== "_ADD_" && node.table){
createFieldList();
}
$('#node-input-table-fetch-fields').click(function(e) {
createFieldList();
e.preventDefault();
});
$('#node-input-table').keypress(function (e) {
if (e.which == 13) {
createFieldList();
return false;
}
});
$("#node-input-target-field-checkbox-all").change(function() {
$(".node-input-target-field-checkbox").prop('checked',this.checked);
});
}, // oneditprepare
oneditsave: function() {
var node = this;
node.selectedFields = [];
$(".node-input-target-field-checkbox").each(function(n) {
if ($(this).prop("checked")) {
node.selectedFields.push($(this).data('field-id'));
}
});
}, // oneditsave
});
</script>
<script type="text/x-red" data-template-name="field list">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<label for="node-input-table"><i class="icon-tag"></i> Table</label>
<input type="text" id="node-input-table" placeholder="MARA">
</div>
<div class="form-row">
<label for="node-input-condense"><i class="icon-tag"></i> Condense</label>
<input type="checkbox" id="node-input-condense" />
</div>
<div class="form-row">
<label for="node-input-system"><i class="icon-tag"></i> System</label>
<input type="text" id="node-input-system">
</div>
<div class="form-tips">
<p>Useful for getting a list of available fields for `read table`.</p>
<p>The output contains an object which describes the specified SAP table. If the `condensed` box is checked, the output will be an object containing only the field name and descriptions.</p>
<p>Use a <strong>Catch</strong> node to catch and process any errors encountered by the RFC.</p>
</div>
</script>
<script type="text/x-red" data-help-name="field list">
<p>Get the field list of an SAP table</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('field list',{
category: 'sapRFC',
color: '#4091ed',
defaults: {
name: {value:""},
table: {value:"", required: true},
condense: {value:"checked"},
system: {type:"saprfc-config", required: true},
},
inputs:1,
outputs:1,
icon: "file.png",
label: function() {
return this.name||"fields of " + this.table;
}
});
</script>