Run a data source after scripted rest api send a payload and I'm filling in the imported table with the data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 01:43 AM
Hi All,
I need your help with data import. The use case is this:
1. I'm getting a complex JSON from a third party system via scripted rest api.
2. I want to process the payload in the scripted rest api and insert the data into a staging table
3. make the import set run.
Is there a beeter way to do this?
Can anyone share how to create an import set and then fill it up and then run it?
Thanks,
Lior
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 02:32 AM
Hi lior
Generally it's set up a web service and corresponding import table and then manage the transform in the transform map with scripts etc.
I have seen preprocessing where you call a script include that queries the JSON and then outputs the various desired elements into the import table. That's however when you are initiating the call with a rest message call.
So to be brief the key bit is handling your JSON and putting the various bits you need into the import set table.
Generally that is the most simple and elegant solution. However there may be a issue where your imported data covers more than one table and chaining transform maps is not viable or simply too messy.
There is a feature called robust import transformer, from the docs it allows you to take data from one source and update multiple different tables in a single transform. It sounds great however I have no direct experience of it and there don't seem to be many useful examples for use cases around. However amybe somethign to look at.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 06:15 AM
Hi Lior,
I'm having the similar requirement now. It would be great help if you shared the steps you followed to achieve this!
Thanks in Advance,
Vishnu R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 06:25 AM
If you configure the import set with an active transform map, the transform should run automatically when you insert into the table using a GlideRecord. Your scripted REST API should work like this:
- Parse JSON payload.
- Loop through each item, if payload is a list.
- Init a GlideRecord on the staging table (staging table must be child of sys_import_set_row).
- Insert a new record into the staging table.
If that doesn't work, you can use GlideImportSetTransformer:
GlideImportSetTransformer - Scoped, Global
- Create an Import Set table using the GlideImportSetTable API.
- Create a Transform Map using the GlideImportSetTransformMap API.
- Create or use an existing Import Set using the GlideRecord API.
- Execute an Import Set Transform using the GlideImportSetTransformer API.
var transformer = new GlideImportSetTransformer(); transformer.transformAllMaps(importSetGr);