Donte Hooker, Author at ServiceNow Guru https://servicenowguru.com/author/dontehooker/ ServiceNow Consulting Scripting Administration Development Mon, 04 Nov 2024 16:09:19 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://servicenowguru.com/wp-content/uploads/2024/05/cropped-SNGuru-Icon-32x32.png Donte Hooker, Author at ServiceNow Guru https://servicenowguru.com/author/dontehooker/ 32 32 Exporting Records to CSV Using ServiceNow Flow Designer https://servicenowguru.com/design/exporting-records-to-csv-using-servicenow-flow-designer/ Tue, 05 Nov 2024 10:00:22 +0000 https://servicenowguru.com/?p=17011 Exporting data from ServiceNow is a common requirement for many organizations, whether for reporting, data analysis, or integration with other systems. One of the powerful features of ServiceNow is the Flow Designer, which allows you to automate processes without writing code. In this post, we will walk through how to create a Flow in ServiceNow

The post Exporting Records to CSV Using ServiceNow Flow Designer appeared first on ServiceNow Guru.

]]>
Exporting data from ServiceNow is a common requirement for many organizations, whether for reporting, data analysis, or integration with other systems. One of the powerful features of ServiceNow is the Flow Designer, which allows you to automate processes without writing code. In this post, we will walk through how to create a Flow in ServiceNow that exports records to a CSV file.

Prerequisites

Before we begin, ensure you have the following:

– Admin access to ServiceNow: You’ll need the necessary permissions to create and manage Flows.
– Knowledge of Flow Designer: Basic understanding of how Flow Designer works.
– Records to Export: Identify the records or the table you want to export.

Step 1: Identify the Records to Export

First, determine the table from which you want to export records. For example, you might want to export incident records, change requests, or custom records. Let’s say you want to export incident records that are in the “Resolved” state.

Step 2: Create a New Flow

1. Navigate to Flow Designer: Go to the application navigator and type `Flow Designer`. Click on it to open the Flow Designer interface.

2. Create a New Flow:
– Click on `+ New` to create a new Flow.
– Give your Flow a meaningful name, such as “Export Resolved Incidents to CSV.”

 

Step 3: Add a Trigger

The Flow needs a trigger to start the process. Depending on your requirement, you can choose different types of triggers.

– Scheduled Trigger: This allows you to export records at regular intervals (e.g., daily, weekly).
– Click on `+ Add Trigger`.
– Select `Scheduled` as the trigger type.
– Configure the schedule as per your requirement, for instance, daily at midnight.

Step 4: Add an Action to Fetch Records

Now, you need to add an action to fetch the records that you want to export.

1. Add Action:
– Click on `+ Add Action` under the trigger.
– Choose `ServiceNow Core` as the action category.
– Select `Look Up Records` as the action.

2. Configure the Action:
– Choose the table from which you want to fetch records, e.g., `Incident [incident]`.
– Define the conditions to filter the records. For example, `State is Resolved`.
– Store the output in a variable, for instance, `incident_records`.

Step 5: Add an Action to Create CSV Content

To create a CSV file, you need to convert the fetched records into a CSV format.

1. Add Action:
– Click on `+` below the previous action.
– Choose `Script` as the action category.
– Select `Run Script`.

2. Write the Script:
– In the script editor, write a script that converts the records into CSV format. Here’s a sample script:

*javascript*
(function execute(inputs, outputs) {
var records = inputs.incident_records;
var csvContent = “Number,Short Description,State\n”;

records.forEach(function(record) {
csvContent += record.number + ‘,’ + record.short_description.replace(/,/g, ”) + ‘,’ + record.state + ‘\n’;
});

outputs.csvContent = csvContent;
})(inputs, outputs);

– This script assumes that you want to export the incident number, short description, and state.

 

 

Step 6: Add an Action to Save the CSV File

The next step is to save the CSV content as a file in ServiceNow.

1. Add Action:
– Click on `+` below the previous action.
– Choose `ServiceNow Core`.
– Select `Create Record`.

2. Configure the Action:
– Select `Attachment [sys_attachment]` as the table.
– Set the `Table Name` to the table where you want to attach the file, e.g., `Incident [incident]`.
– Provide a name for the file, e.g., `Resolved_Incidents.csv`.
– Set the `Content` field to the `csvContent` variable from the previous script.

Step 7: Test the Flow

Before running the Flow in production, it’s crucial to test it.

1. **Save the Flow**: Ensure all steps are configured correctly and save the Flow.

2. **Test the Flow**: Click on `Test` to manually trigger the Flow and verify that it works as expected.

Step 8: Activate the Flow

Once you have tested the Flow and confirmed it works correctly, activate it by toggling the Flow status to `Active`.

Conclusion

With this Flow in place, you now have an automated process to export records from ServiceNow to a CSV file. This Flow can be further customized to meet your specific needs, such as exporting different fields, filtering records based on more complex criteria, or integrating the export process with other workflows.

Using ServiceNow’s Flow Designer to export records is a powerful way to automate data handling, saving time and reducing manual effort. Give it a try and see how it can streamline your workflows!

The post Exporting Records to CSV Using ServiceNow Flow Designer appeared first on ServiceNow Guru.

]]>
Using Import Sets for REST Integration in ServiceNow https://servicenowguru.com/integration/using-import-sets-rest-integration/ Mon, 26 Aug 2024 17:18:21 +0000 https://servicenowguru.com/?p=16807 Integrating data from external sources into ServiceNow is a common requirement for organizations aiming to maintain a unified system of record. One effective method for achieving this is through the use of Import Sets, which can be enhanced using REST APIs for seamless data transfer. In this blog post, we will explore how to use

The post Using Import Sets for REST Integration in ServiceNow appeared first on ServiceNow Guru.

]]>

Integrating data from external sources into ServiceNow is a common requirement for organizations aiming to maintain a unified system of record. One effective method for achieving this is through the use of Import Sets, which can be enhanced using REST APIs for seamless data transfer. In this blog post, we will explore how to use Import Sets for REST integration in ServiceNow, focusing on key components such as Transform Maps, Transform Scripts, and the Import Set API.

What are Import Sets?

Import Sets in ServiceNow are used to import data from various data sources and map that data into ServiceNow tables. They act as staging tables where raw data is initially stored before being processed and transformed into the target tables in ServiceNow.

Transform Maps

Definition

A Transform Map is a set of field mappings that determines the relationships between fields in an import set and fields in the target table. Transform Maps ensure that the data imported from the staging table is correctly mapped and transferred to the desired table in ServiceNow.

Creating Transform Maps

  1. Navigate to: System Import Sets > Administration > Transform Maps.
  2. Click on New to create a new transform map.
  3. Provide a name for the Transform Map and select the source Import Set Table and the Target Table.
  4. Define field mappings by adding field map records, specifying the source field from the Import Set Table and the target field in the ServiceNow table.

Transform Maps Validation

  • Ensure the Transform Map is reusable by defining source and target tables that can be applied to multiple data imports.
  • Use the Auto Map Matching Fields feature to automatically map fields with the same name.
  • Validate the field mappings by testing with sample data to ensure accuracy.

Transform Scripts

Definition

Transform Scripts are server-side JavaScript that can be used to manipulate data during the transformation process. These scripts provide additional flexibility to handle complex data transformations and custom logic.

Types of Transform Scripts

  1. onBefore: Executed before any record is processed.
  2. onStart: Executed at the start of the transformation.
  3. onAfter: Executed after each record is processed.
  4. onComplete: Executed after all records have been processed.

Example Usage

(function transformRow(source, target, map, log, isUpdate) {
// Example: Set a default value if a field is empty
if (!source.field_name) {
target.field_name = ‘Default Value’;
}
})(source, target, map, log, isUpdate);
Import Set API

The Import Set API allows for the import of data into ServiceNow from external sources using RESTful web services. This API provides endpoints to create, update, and delete records in Import Set Tables.

Key Endpoints

  1. POST /api/now/import/{table_name}: Import data into a specified Import Set Table.
  2. GET /api/now/import/{table_name}: Retrieve data from a specified Import Set Table.
  3. PUT /api/now/import/{table_name}/{sys_id}: Update a record in a specified Import Set Table.
  4. DELETE /api/now/import/{table_name}/{sys_id}: Delete a record from a specified Import Set Table.

Example Usage

To import data into an Import Set Table using REST, you can use the following example:

Request:

POST /api/now/import/u_my_import_table
Content-Type: application/json
Authorization: Bearer {your_token}{
“field1”: “value1”,
“field2”: “value2”,

}

Response:

{
“status”: “success”,
“sys_id”: “1234567890abcdef”
}

Sample REST API Call using PostMan

 

Integrating It All Together

  1. Setup Import Set Table: Create or identify the Import Set Table where data will be initially stored.
  2. Define Transform Map: Create and configure a Transform Map to map fields from the Import Set Table to the target table.
  3. Write Transform Scripts: Add any necessary Transform Scripts to handle custom logic and data manipulation.
  4. Use Import Set API: Utilize the Import Set API to import data from external sources into the Import Set Table.
  5. Run Transform: Execute the Transform Map to move data from the Import Set Table to the target table, applying any Transform Scripts in the process.

Conclusion

Using Import Sets for REST integration in ServiceNow provides a robust solution for importing and transforming data from various external sources. By leveraging Transform Maps and Transform Scripts, you can ensure that data is accurately and efficiently mapped to your ServiceNow tables. The Import Set API further enhances this process by allowing seamless integration through RESTful web services. By following these best practices and utilizing the tools provided by ServiceNow, you can achieve a streamlined and effective data import process.

The post Using Import Sets for REST Integration in ServiceNow appeared first on ServiceNow Guru.

]]>