HR Integrations : Retrieving Multiple Records with Same person_id_external in CompoundEmployee API

Aniket16
Tera Contributor

Hello ServiceNow Community,

I'm working with the CompoundEmployee API (HR Integrations : Worker Profiles), and I've encountered a situation where there are two records with the same person_id_external. Currently, my API request only retrieves one of these records. I would like to know what changes I can make in my API request to retrieve both records associated with the same person_id_external. Any guidance or examples would be greatly appreciated.

Thank you!

This is my current API request :

Aniket16_0-1695041466271.png

 

6 REPLIES 6

Aniket16
Tera Contributor

Thank you for your suggestion @JamesEcoStratus! However, I'm looking to retrieve all records associated with all person IDs, not just a specific one. The challenge I'm facing is that there are multiple records with different person IDs, and I want to include all of them in the API response. Is there a way to modify the API request to retrieve all records without specifying a single person_id_external value?

Your help is greatly appreciated!

Hi, Let’s take a step back and try this again.

 

Current Challenge: I understand your need to retrieve multiple records associated with different person_id_external values from the ServiceNow CompoundEmployee API. The challenge you're facing is that the API typically requires specifying a single person_id_external value in the request, making it challenging to retrieve data for multiple individuals at once.

 

Potential Approaches to Address:

Here are some options you could use to address this challenge:

 

  1. Batch API Requests:
  • ServiceNow's REST API supports batch requests, allowing you to bundle multiple individual API requests into a single batch request.
  • Each individual request in the batch can specify a different person_id_external. This approach is suitable when you have a predefined list of person_id_external values that you want to retrieve data for in a single API call.
  • Alternative Approach: You can create a script or program that generates and sends a batch API request dynamically based on the list of person_id_external values you need to query. The response will contain data for all specified individuals.
  1. Scripted REST API:
  • If you have scripting capabilities in your ServiceNow instance, you can create a custom Scripted REST API that accepts a list of person_id_external values as input parameters.
  • The script can then iterate through the list, making individual calls to the CompoundEmployee API for each person_id_external value and aggregating the results.
  • Alternative Approach: This custom Scripted REST API can be designed to retrieve data for multiple individuals without the need to manually specify each person_id_external value in the request.
  1. Scheduled Jobs:
  • If you need to retrieve data for a large number of person_id_external values regularly, consider creating a scheduled job within ServiceNow.
  • This job can run periodically, fetching data for different individuals and storing it in a designated location, such as a table or an external system.
  • Alternative Approach: The scheduled job can be configured to retrieve data for multiple person_id_external values over time, ensuring that you have the most up-to-date information.
  1. Integration Middleware:
  • Utilize integration middleware or platforms like MuleSoft, Dell Boomi, or Zapier to connect with ServiceNow.
  • These platforms often provide capabilities to aggregate data from multiple sources, including ServiceNow, and transform it to meet your specific requirements.
  • Alternative Approach: You can configure integration workflows to retrieve data for multiple person_id_external values concurrently, streamlining the data retrieval process.

 

Each of these approaches offers a way to retrieve data for multiple person_id_external values from the ServiceNow CompoundEmployee API. The choice of method depends on your specific use case, technical capabilities, and integration requirements. You may want to consult with your ServiceNow team to determine the most suitable approach based on your organization's needs.

 

Here are examples for each of the script options mentioned:

  1. Batch API Requests:
  • Suppose you have a list of person_id_external values to retrieve data for, such as ["123", "456", "789"]. You can create a batch request like this in a script:
 
  1. Scripted REST API:
  • In your ServiceNow instance, create a new Scripted REST API. Define an endpoint that accepts a list of person_id_external values as a parameter. The script can then iterate through the list, make individual calls to the CompoundEmployee API, and aggregate the results.

 

Here's a simplified example in Javascript:

 

Screenshot 2023-09-21 at 15.06.43.png

 

  1. Scheduled Jobs:
  • Create a scheduled job in your ServiceNow instance that runs periodically. This job can be configured to fetch data for different individuals and store it in a designated location, such as a table.

 

Here's a simplified example using a scripted scheduled job:

 

 

Screenshot 2023-09-21 at 15.03.03.png

 

 

  1. Integration Middleware:
  • If you're using an integration middleware like MuleSoft, you can configure an integration flow to retrieve data for multiple person_id_external values concurrently. The middleware will handle the orchestration and transformation of data. The exact configuration would depend on the middleware platform you're using.

 

These examples provide a starting point for implementing each approach. You'll need to adapt them to your specific requirements and environment and consider error handling and data storage as needed.

 

Good Luck!

James @Ecostratus

If I helped you with your question, then please hit the Thumb Icon and mark it as Helpful or Correct.