Establishing two-way communication between ServiceDesk Plus and ServiceNow is done in 4 steps.
It can be achieved using Python scripts by installing Python runtime in builds older than 11120 but with newer builds, it can be done with Deluge scripts and the built-in Deluge runtime.
Deluge does not support username-password encoding. Hence it has to be manually encoded and updated in the configuration file.[FileName: global_function_4-ServiceNow_Configurations.txt]
For builds older than 11120, check the procedure in this link.,
From ServiceDesk Plus:
1. Creating a ServiceNow ticket when a SDP ticket is created
2. Closing a ServiceNow ticket when a SDP ticket is closed
From ServiceNow:
3. Creating a ServiceDesk Plus ticket when a ServiceNow ticket is created
4. Closing a ServiceDesk Plus ticket when a ServiceNow ticket is created
Create an additional field in ServiceDesk Plus:
1. We need to create two additional fields
ServiceNow Id --> For storing the ticket Id from ServiceNow
Go to Admin > Incident - Additional fields > Add field > Create a single line additional field and note down the API Field Name
ServiceNow sys_id --> For storing the ServiceNow incident sys_id (By using sys_id we can close the ticket in ServiceNow using API)
Goto Admin > Incident - Additional fields > Add field > Create a single line additional field and note down the API Field Name
2. Add the newly created additional fields to the incident template.
Creating Additional Field in ServiceNow:
1. We need one additional field to hold the ServiceDesk Plus ticket id.
2. Login to ServiceNow and search Incidents > Click the incidents tab > Click New button as shown below
3. Click on Additional Actions > Configure > Form Layout
4. Create a new additional field called "SDP Ticket ID" and make sure created field is available under Selected fields
5. Once additional field is created, we need to find out the ID to make API call. Create a dummy incident request > Edit the request > Inspect element and get the additional field id
Creating a ServiceNow ticket when a SDP ticket is created
Steps to configure:
1. ServiceNow configuration informations are stored in servicenow_config.json
2. For Python:
- Download and extract the python_integration.zip
- Move create_servicenow.json, functions.py, configuration.json, create_servicenow_ticket.py,servicenow_config.json files to MangeEngine/ServiceDesk/integration/custom_scripts folder
- Edit configuration.json and update url and technician_key
- Edit servicenow_config.json and update servicenow configurations like url,username,password
- url >> ServiceNow server url (sample : https://dev79461.service-now.com%29/
- username >> SeriviceNow username
- password >> ServiceNow password
- update api_fields >> fields mapping between SDP to Servicenow
3. For Deluge:
- Download the attached scripts. Copy the contents into request custom functions.
- Goto Admin > Request Custom Function > Custom Function > New > Paste the custom function content
- Goto Admin > Request Custom Function > Global Function > New > Paste the global function contents.
4. Create a Custom Trigger to get executed when a request is created.
Criteria: ServiceNow_ID is Null
Action Executor:
Python: py create_servicenow_ticket.py $COMPLETE_V3_JSON_FILE
Deluge: Select the create - custom function
5. If a ticket is created with required criteria, the ServiceNow script gets executed and the respective additional fields gets populated.
Closing a ServiceNow ticket when a SDP ticket is closed
Steps to configure:
1. Create a Custom Trigger in SDP as shown below
2. Move close_servicenow_ticket.py file to MangeEngine/ServiceDesk/integration/custom_scripts folder
3. Resolution notes, Resolution code are mandatory for closing a ServiceNow ticket.
4. We can either move the SDP Resolution and Request Closure Code to ServiceNow or we can use the static content in the script directly
Note: ServiceNow Resolution code and SDP Request Closure Code must be same in order to close the Servicenow ticket.
Dynamic Content:
Static Content:
5. If the custom trigger/menu gets executed, the respective Servicenow ticket will also be closed.
Creating a SDP ticket when a ServiceNow ticket is created
We are using System Web Services - Rest Message + System Definition - Business rules + SDP request API for creating a request in SDP from ServiceNow
Creating a System Web Services - Rest Message
1. Connect to ServiceNow and Rest Message as shown below
2. Click on Rest Message > Click New button
3. Create a New Rest message as shown below and Submit the form
4. Once the Rest message is created, we need to create a Post Call method for creating a request in SDP. Edit the created Rest message > Under Http methods > Click New button
5. Create New Http method as shown below
6. As we are using the SDP request API we need to add the TECHNICIAN_KEY and input_data for this click HTTP Request tab and add a technician key under HTTP Header as shown below
7. Now we need to add the input_data under HTTP Query Parameters,
As we need to pass the ServiceNow content we can add the dynamic variable to the input_data value as shown below
8. Now submit Http Request action and update Rest Message
9. We can see the default HTTP methods available for the Rest Message under Http Methods
10. For testing the HTTP post action we need to substitute the $values with some dummy content,
Edit created Rest Message > Edit Post method > Click Auto-generate variables link under Related Links as shown below
11. On clicking Auto-generate variables dynamic variables will be automatically created under Variable Substitutions.
Refer the screenshot
12. Give some test value for the variable substitutions field and click the Test link under Related Links to check the API POST call
13. After clicking Test link we can see the API response as shown below and a new request is created in SDP
14. Once API call is success we need to copy the script that is used for the POST call, For this click the Preview Script Usage under Related Links and copy the content
A sample script content as follows
try {
var r = new sn_ws.RESTMessageV2('Create SDP Ticket', 'Post method');
r.setStringParameterNoEscape('id', 'INC09839473');
r.setStringParameterNoEscape('subject', 'Test Subject');
r.setStringParameterNoEscape('sys_id', 'ioadfjkabsdhfgasifh');
r.setStringParameterNoEscape('description', 'Test Description');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
Creating a Business Rule
1. Connect to ServiceNow and search Business Rules as shown below and Click the New button
2. Create a Business rule values as shown below
3. Edit the created Business Rule and click Advanced tab for pasting the script that we copied in the previous steps, Here we will replace the dummy content with dynamic values and will replace the \n values with br for the description field and also printing the API response and update the Business rule
Refer the screen shot
4. Go to Incidents and create a new Incident in ServiceNow
If the Business rule matches a new ticket will be created in SDP and we are printing the API response in the incident list view as shown below so that we can check the API response
5. Once ticket is created in SDP we need to update the ServiceNow additional field with SDP Id.
6. Move update_servicenow_field.py file to MangeEngine/ServiceDesk/integration/custom_scripts folder
Create a Custom Trigger in SDP as shown below
Executor :
py update_servicenow_field.py $COMPLETE_V3_JSON_FILE
Closing a SDP Ticket when a ServiceNow ticket is Closed
1. We are using System Web Services - Rest Message + System Definition - Business rules + SDP request API for closing a request in SDP
2. Similar to the Rest-Message POST method we will use PUT method for closing the SDP request
3. Go to earlier created Rest Message action --> Edit the action --> Create new button under Http methods
4. Fill the details as shown below and save the action
As we need to pass the SDP Id in the end_point URL we need to add the dynamic value here ${sdp_id}
input_data for close request as follows
Note: We can pass the dynamic values also in the input_data similar to how we add for add request
{
"request": {
"closure_info": {
"requester_ack_resolution": true,
"requester_ack_comments": "Mail fetching is up and running now",
"closure_comments": "Reset the pasword solved the issue",
"closure_code": {
"name": "success"
}
}
}
}
5. Save the action and we can add the dummy entry for the $variable similarly how we added for the POST call
6. Test the API call from Related Links > Test and we can check the API response here
7. Copy the Script content from Related Links > Preview script usage
8. Now we need to create a one Business rule in Servicnow
Criteria : When incident is closed
Advanced level : Execute the above copied script similarly how we did it for add request
Note: we need to replace the $sdp_id with current.u_sdp_ticketId
9. Now when a ticket is closed in ServiceNow, SDP ticket will be closed automatically