Skip to content

Commit e39995c

Browse files
authored
Create script for concatenating
Use Case: Script for concatenating while sending it to target system . Using existing steps (without scripting), it is very difficult to send a concatenated script By using the this step with a simple script, we can concatenate and send it to third party system.
1 parent 0e05c51 commit e39995c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

script for concatenating

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(function execute(inputs, outputs) {
2+
function jsonEncode(str) {
3+
var stri = new JSON().encode(str);
4+
return stri.substring(1, stri.length - 1);
5+
}
6+
7+
var remarks = '';
8+
var target = new GlideRecord('incident');
9+
target.addQuery('number', inputs.number);
10+
target.query(); // Issue the query to the database to get relevant records
11+
while (target.next()) {
12+
13+
remarks = remarks + "Priority : " + target.priority.getDisplayValue();
14+
15+
if (target.u_incident_manager_required) {
16+
remarks = remarks + "\\r\\nIncident Manager Requested = Yes";
17+
remarks = remarks + "\\r\\nReason for Incident Manager requested = " + jsonEncode(target.u_reason_for_incident_manager + '');
18+
}
19+
20+
if (target.u_escalation) {
21+
remarks = remarks + "\\r\\nEscalation = Yes";
22+
remarks = remarks + "\\r\\nReason for escalation = " + jsonEncode(target.u_escalation_reason + '');
23+
}
24+
var grWorknotes = new GlideRecord('sys_journal_field');
25+
grWorknotes.addQuery('element_id', inputs.journalid);
26+
grWorknotes.addQuery('element', 'work_notes');
27+
grWorknotes.addEncodedQuery('sys_updated_by!=test_API^sys_updated_by!=system');
28+
grWorknotes.orderByDesc('sys_created_on');
29+
30+
grWorknotes.query();
31+
if (grWorknotes.next()) {
32+
if (inputs.work_notes) {
33+
remarks = remarks + "\\r\\nWork Notes : " + jsonEncode(grWorknotes.value.toString());
34+
}
35+
}
36+
37+
38+
39+
var grComments = new GlideRecord('sys_journal_field');
40+
grComments.addQuery('element_id', inputs.journalid);
41+
grComments.addQuery('element', 'comments');
42+
grComments.orderByDesc('sys_created_on');
43+
44+
grComments.query();
45+
if (grComments.next()) {
46+
if (inputs.comments) {
47+
remarks = remarks + "\\r\\nAdditional comments : " + jsonEncode(grComments.value.toString());
48+
}
49+
}
50+
}
51+
if (!inputs.journalid) {
52+
remarks = inputs.work_notes;
53+
}
54+
outputs.remark = remarks;
55+
56+
})(inputs, outputs);

0 commit comments

Comments
 (0)