how to setup the third-party integration using HR integration in HRSD.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2025 04:23 AM
Hii good evening!
I'm working on outbound integration using HR integrations for that I have created one source, HR schema mapping, HR service mapping, HR outbound integration mapping and HR rest Services connection is done between the third party, how can we schedule the outbound updates to third party once the setup is done?
Please provide me the code how to schedule it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2025 04:40 AM - edited ‎03-19-2025 04:41 AM
Hi Apoorva,
Once the HR outbound integration setup is complete, you need to schedule the outbound updates to the third party. This can be done using Scheduled Job (Scheduled Script Execution) in ServiceNow.
Steps to Schedule Outbound Updates
Ensure your HR integration setup is complete (which you have done).
Create a Scheduled Script Execution to trigger the outbound integration at regular intervals.
Use a Script to Query HR Data and Send it to the Third Party via the HR REST Service.
1. Create a Scheduled Script Execution
Navigate to System Definition → Scheduled Jobs → New.
Set the Type to "Script".
Choose a Run Time (e.g., every 30 minutes or daily).
Add the below script to execute the outbound HR integration.
2. Scheduled Script Execution Code
This script:
Queries the sn_hr_core_case table for newly updated HR cases.
Calls the HR REST API Service to send data.
Updates a custom field (integration_status) to track sent records.
(function executeHRIntegration() {
gs.info("HR Outbound Integration Scheduled Job Started");
var hrCases = new GlideRecord('sn_hr_core_case');
hrCases.addQuery('state', 'closed'); // Example: Only send closed cases
hrCases.addQuery('integration_status', '!=', 'sent'); // Avoid duplicate sends
hrCases.query();
while (hrCases.next()) {
var payload = {
case_number: hrCases.number.toString(),
short_description: hrCases.short_description.toString(),
assigned_to: hrCases.assigned_to.getDisplayValue(),
closed_at: hrCases.closed_at.toString(),
case_type: hrCases.case_type.toString(),
additional_info: hrCases.description.toString()
};
var response = sendHRDataToThirdParty(payload);
if (response && response.status == 200) {
hrCases.integration_status = "sent";
hrCases.update();
gs.info("HR Case " + hrCases.number + " sent successfully.");
} else {
gs.error("Failed to send HR Case " + hrCases.number + ". Response: " + JSON.stringify(response));
}
}
gs.info("HR Outbound Integration Scheduled Job Completed");
})();
/**
* Function to send HR Data to the third-party system using REST API
* @Param {Object} payload - HR case data
* @returns {Object} response - API response
*/
function sendHRDataToThirdParty(payload) {
try {
var restMessage = new sn_ws.RESTMessageV2('HR_Integration_REST_Service', 'default'); // Replace with your HR REST Service name
restMessage.setRequestBody(JSON.stringify(payload));
restMessage.setHttpMethod("POST");
var response = restMessage.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();
return {
status: httpStatus,
body: responseBody
};
} catch (error) {
gs.error("HR Outbound Integration Error: " + error.message);
return {
status: 500,
body: error.message
};
}
}
3. Configuration in Scheduled Job
Run As: System User
Run Time: Set the frequency (e.g., every 30 mins or daily).
Active: ✅ Enabled.
4. Expected Behavior
Every scheduled run, it fetches HR cases that are closed and not yet sent.
Sends the data to the third-party API.
Updates integration_status to "sent" after a successful response.
Logs success or failure messages.
5. Enhancements (Optional)
✅Error Handling & Retries: Store failed cases and retry.
✅Data Filters: Customize queries to include only required cases.
✅Dynamic Scheduling: Use Event-based triggers instead of Scheduled Jobs.
This approach ensures a robust and automated HR outbound integration.
This should solve your issue!
Kindly mark it as "Accepted Solution"/"helpful", as it resolves your query. Please press like button for the resolution provided.
With Regards,
Krishna Kumar M - Talk with AIT3ch
LinkedIn: https://www.linkedin.com/in/mkrishnak4/
YouTube: https://www.youtube.com/@KrishAIT3CH
Topmate: https://topmate.io/mkrishnak4 [ Connect for 1-1 Session]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2025 05:30 AM
Hii Krishna
Whatever you have provided is a normal way of integration with third party, but I have created a outbound schema mapping where the data flows to the third-party using HRSD we need to configure.