Saturday, June 29, 2019

Outbound REST Message of ServiceNow

In ServiceNow, there are two ways to generate REST Message
      1. Outbound REST message
      2. Scripting REST Message

In Server Side Script, we can directly use “new sn_ws.RESTMessageV2()” to generate REST Message object without creating “Outbound REST Message” in Studio. But it is not handy to test and debug it. In contrast, “Outbound REST Message” provide an easy way to test it and show it in build-in GUI. It can shorten our development time.

Therefore, in this demonstration, I will focus on “Outbound REST message”.

Preparation

1. Generate a new instance in ServiceNow for this demonstration

2. Go through the pages of Postman Echo to understand how to send REST request to it. We can take advantage of “Postman Echo” to test our REST clients directly, instead of building our own Web Server.

Demonstration

HTTP GET

1. In ServiceNow Studio, click “Create Application File” button on the top, and select “REST Message” and then click “Create





2. Fill the form’s Name, Description and Endpoint.

Set “Endpoint” to “https://postman-echo.com/get?foo1=${foo1}&foo2=${foo2}”. You can refer to the "Postman Echo" website. Also, select “Authentication type” as “No authentication



3. Once you save it, the default HTTP methods (Default GET) will be generated automatically. Click it to edit. You can change the name of it if you want.

4. Continue the previous step, click “Auto-generate variables”. Then, you will notice that two new records inserted in “Variable Substitutions”. In order to use Outbound REST Message’s test function, set the “Test value” for those variable substitutions.



5. Click “Test”, then you will see the REST testing result. 



HTTP POST

1. In ServiceNow Studio, click “Create Application File” button on the top, and select “REST Message” and then click “Create

2. Fill the Name, Description and Endpoint.

Set “Endpoint” to “https://postman-echo.com/post”. You can refer to the "Postman Echo" website. Also, select “Authentication type” as “No authentication



3. Once you save it, the default HTTP methods (Default GET) will be generated automatically. Click it to edit. Change it to “Post” in HTTP method field.

4. Continue to the previous step, insert “accept” and “content-type” with “application/json” value. Also, fill the Content field as the following picture.



5. Click “Test”, then you will see the REST testing result. 


Wednesday, June 19, 2019

Customize ServiceNow baseline form

We can use “Form Design” to change the form view easily if the information we want to add is existed in its relating table record. However, if those information is not stored in form’s relating table, we could use UI Formatter and UI Macros to customize the form view.

Below is a demonstration steps-by-steps.

1.  First, we need to create a new app for this demonstration

    Open “Studio” -> “Create Application” -> select “Start from scratch”, and enter your application name.


 2. Second, we need to create an “UI Macro” to define the content which will be used by “UI formatter”

    On studio, click “Create Application File”, and select “UI Macro

 
     


3. Then, we need to create an “UI formatter” which need to point out which “UI Macros” it will use.

On studio, click “Create Application File”, and select “UI formatter

Note that, the field of “Formatter” should be the name of “UI Macros” you want to use, and end with the “.xml
    
   
    


4. In the end, we need to add the defined formatter to the form view we want to change.

On studio, click “Create Application File”, and select “Form” -> Create

In this demonstration, I select “Default View” of “Incident [incident]” and add the formatter we created to it.




5.The Application Files structure will be shown as following.


   


6. To test it, open any record from Incident table, you can see the new tab we created through “UI formatter” and “UI Macros”.