Third party integration with my PDI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2024 05:16 AM
Hi,
I want to learn integrations in ServiceNow. I've tried integrating 2 ServiceNow instances. Now I want to try integrating my PDI with 3rd party applications. Can anybody tell me any 3rd party applications and use cases with which I can try integrations and get my hands dirty. If anyone could provide any articles or tutorials that would be great.
Regards,
Vasu Ch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2024 05:35 AM
Hi @Vasu ch
I would recommend you to do third party integration with Salesforce using oAuth 2.0 You can have free developer instance from here just like ServiceNow-
https://developer.salesforce.com/
Use case- Whenever a case/incident in created in ServiceNow, that needs to be passed to Salesforce
You need to setup REST message with endpoints, authentication profile etc. and trigger it with the help of Business Rules. Alternatively, you can pass the endpoints, authentication etc in business rule itself. Sharing an outline of business rule with you.
(function executeRule(current, previous /*null when async*/ ) { try { var client_id = 'Enter your client id'; var client_secret = 'Enter your client secret'; var grant_type = 'client_credentials'; var token_endpoint = 'https://*****prodtest.sandbox.my.salesforce.com/services/oauth2/token'; var token_grant_url = token_endpoint + "?grant_type=" + grant_type + "&client_id=" + client_id + "&client_secret=" + client_secret; var token_request = new sn_ws.RESTMessageV2(); token_request.setEndpoint(token_grant_url); token_request.setHttpMethod("post"); var token_response = token_request.execute(); var response_body = token_response.getBody(); var response_obj = JSON.parse(response_body); var access_token = response_obj.access_token; gs.info('Token request response: ' + response_body); gs.info('Access token: ' + access_token); // Use the access token to make API calls var api_request = new sn_ws.RESTMessageV2(); api_request.setEndpoint('https://*****prodtest.sandbox.lightning.force.com/services/data/v58.0/sobjects/case'); api_request.setHttpMethod('post'); api_request.setRequestHeader('Authorization', 'Bearer ' + access_token); api_request.setRequestHeader('Accept', 'application/json'); api_request.setRequestHeader('Content-Type', 'application/json'); var restObj = { "Contact__c": current.contact.name + '', "ServiceNow_SysID__c": current.sys_id + '', "Priority__c": current.priority.getDisplayValue() + '', "Subcategory__c": current.subcategory + '', "Number__c": current.number + '', "Assignment_Group__c": current.assignment_group.name + '', "Assigned_to__c": current.assigned_to.name + '', "Channel__c": current.contact_type.getDisplayValue() + '', "Short_Description__c": current.short_description.toString().replace(/\v|\r|\0/g, "") + '', "Description__c": current.description.toString().replace(/\v|\r|\0/g, "") + '' }; var restStr = JSON.stringify(restObj); api_request.setRequestBody(restStr); gs.info('API Request Endpoint: ' + api_request.getEndpoint()); gs.info('API Request Headers: ' + api_request.getRequestHeaders()); var api_response = api_request.execute(); var api_response_body = api_response.getBody(); var httpStatus = api_request.getStatusCode(); if((httpStatus != 200) && (httpStatus != 201)){ gs.eventQueue("httpStatusFailed", current, current.number, api_response_body); } gs.info('API Response Object: ' + api_response); gs.info('API Response Body: ' + api_response_body); gs.info(current.number + "\nSalesforce Case Create : HTTP Status : " + api_response.getStatusCode() + "\nRequest Body : " + api_request.getRequestBody() + "\nResponse Body : " + api_response_body); } catch (error) { gs.error('An error occurred: ' + error); } })(current, previous);
Please mark my answer helpful and correct.
Regards,
Amit Pandey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2024 08:28 AM
Hi @Vasu ch ,
Please have a look at the great article by John having various resources related to integration.
ServiceNow Popular Integration resources
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
Mark this as Helpful / Accept the Solution if this helps.