RiteshSwarnakar
Giga Guru

1] Create a REST Message on source Instance and specify the Target instance Incident table URL and also create a Basic authentication type(:

find_real_file.png

 

 

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:

find_real_file.png

 

3] Finally create a Business Rule and use the below script in the Business Rule :

find_real_file.png

 

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

Version history
Last update:
‎10-12-2021 08:18 AM
Updated by: