RiteshSwarnakar
Giga Guru
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 10-12-2021 08:18 AM
1] Create a REST Message on source Instance and specify the Target instance Incident table URL and also create a Basic authentication type(:
2] Create a PUT (HTTP method), specify the target URL with a variable name as shown below. Payload is created in the BR itself. Create HTTP Headers as shown below and then click on Auto-generate variables:
3] Finally create a Business Rule and use the below script in the Business Rule :
Note: we require the sys_id of the target Incident record. We can fetch it using the GET method. Here I have parsed the response from the POST method: Click here
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2('Ebonding', 'PUT');
r.setStringParameterNoEscape('sys_id', current.getValue("correlation_id"));
var ob = {};
if (current.getValue("description") == null) {
if (current.work_notes.changes() && current.comments.changes()) {
var ob = {
comments: current.comments.getJournalEntry(1),
work_notes: current.work_notes.getJournalEntry(1),
state: current.getValue("state"),
description: ""
};
} else if (current.work_notes.changes()) {
var ob = {
work_notes: current.work_notes.getJournalEntry(1),
state: current.getValue("state"),
description: ""
};
} else if (current.comments.changes()) {
var ob = {
comments: current.comments.getJournalEntry(1),
state: current.getValue("state"),
description: ""
};
}
} else if (current.getValue("description") !== null) {
if (current.work_notes.changes() && current.comments.changes()) {
var ob = {
comments: current.comments.getJournalEntry(1),
work_notes: current.work_notes.getJournalEntry(1),
state: current.getValue("state"),
description: current.getValue("description")
};
} else if (current.work_notes.changes()) {
var ob = {
work_notes: current.work_notes.getJournalEntry(1),
state: current.getValue("state"),
description: current.getValue("description")
};
} else if (current.comments.changes()) {
var ob = {
comments: current.comments.getJournalEntry(1),
state: current.getValue("state"),
description: current.getValue("description")
};
}
}
r.setRequestBody(JSON.stringify(ob));
var response = r.execute();
var responseBody = response.getBody();
// gs.addInfoMessage(responseBody);
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Regards,
Ritesh
#Rome #Scripting #Business Rule
- 2,862 Views