integrations

Automate sending data from ServiceNow to MidlEO on incident creation

Author: Vasil Vasilev
July 27, 2023

ServiceNow and MidlEO platforms support REST integration. That is why you can easily make an integration between both of them.
For example, when an incident is created in ServiceNow, the data is automatically sent to my MidlEO system, triggering ticket creation and middleware automation based on the workflow logic behind it.
Here are the steps.


ServiceNow Business Rules

A Business rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried.
If someone opens an incident, you can define a Business rule to run.

ServiceNow's RESTMessageV2 API

In the Business Rules advanced configuration, you can trigger custom scripts. For this purpose, you need ServiceNow RESTMessageV2 API. The RESTMessageV2 API allows you to send outbound REST messages using JavaScript.

How to configure

  1. In your ServiceNow instance, go to System Definition > Business Rules.
  2. Select New.
  3. Give your new Business Rule a name, choose what table you want it to trigger on (Incident in our case), and check the Advanced box.
  4. Next, choose After for when you want it to run. In this case, the data will be sent after the Incident is created
  5. navigate to the Advanced tab. In the Script editor, add the following code. Make sure to replace it with your Middleware Admin application URL. Should be in this form: https://server.domain/extapi

(function executeRule(current, previous ) {
    try {
        var r = new sn_ws.RESTMessageV2();
        r.setEndpoint("https://server.domain/extapi");
        r.setHttpMethod("post");
        var usr = new GlideRecord('sys_user');
        usr.get('sys_id', current.getValue("caller_id"));
        var useremail = usr.getValue('email');
        var userid=gs.getUserID();
        var username=gs.getUserName();
        var number = current.getValue("number");        
        var opened_at = current.getValue("opened_at");
        var short_description = current.getValue("short_description");
        var description = current.getValue("description");
        var service = current.getValue("service_offering");
        var confitem = current.getValue("cmdb_ci");
        var category = current.getValue("category");
        var priority = current.getValue("priority");
        var sys_id = current.getValue("sys_id");
        var subcategory = current.getValue("subcategory");
        var state = current.getValue("state");

        var obj = {
            "number": number,
            "useremail": useremail,
            "userid": userid,
            "username": username,
            "opened_at": opened_at,
            "short_description": short_description,
            "description": description,
            "category": category,
            "priority": priority,
            "sys_id": sys_id,
            "subcategory": subcategory,
            "service": service,
            "confitem": confitem,
            "state": state,
            "action": "snowticket",
            "appcode": service,
            "token": "ss7jhsd91hs", //token taken from midleo.CORE external configuration
            "reqwf":"us8Ky5Tm" //ID can be taken from the midleo.CORE workflow list
        };
        
        var body = JSON.stringify(obj);
        r.setRequestBody(body);
        var response = r.execute();
        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;
        gs.error(message);
    }
    gs.info(httpStatus);
})(current, previous);


reqtype - can be different depending on the desired request type
reqwf - can be taken from the  MidlEO WorkFlow section


Based on the WorkFlow logic, once a MidlEO ticket is opened, it can be automatically processed and sent for deployment, or manual intervention will be needed.

Screenshots from the final solution.

- ServiceNow incident opened




- in the Description, you have to write text in readable YAML format. In this example, the request is for IBM MQ - 3 local queues:

applicationServer: "XXXX"
application: "XXX"
project: "XXX"
serverType: "ibmmq"
requestType: create
applicationType: queues
names:
- name: "TEST1.QL"
descr: "description of the queue"
maxmsgl: 1000
type: "qlocal"
- name: "TEST2"
descr: "description of the queue"
maxmsgl: 2000
type: "qlocal"
- name: "TEST3"
descr: "description of the queue"
maxdepth: 1000
 type: "qlocal"
selectedServer: "XXX"
#you can remove the lines below from the request. it is only a comment
#information about the parameters
#applicationServer - the application server name - IBM MQ, IBM ACE, RabbitMQ - name
#serverType :
#ibmmq - for IBM MQ request
#ibmace - for IBM ACE request
#ibmiib - for IBM IIB request
#requestType: create/update/delete/deploy
#applicationType: queues/channels/topics/intsrv/intapp
#selectedServer: - for IBM ACE/IBM IIB - the Execution group where the package will be deployed


- midleo.CORE ticket opened:




- When there is some update from the midleo.CORE system, you can see the updates in the ServiceNow work notes as well: