npm package: @itentialopensource/generate-query-jst-from-object
Description: Generate a query JST for the object provided
Author: Itential Artifacts
Latest version: 0.0.7-2023.1.0


# Generate Query JST from Object

## Table of Contents

*  [Overview](#overview)
*  [Installation Prerequisites](#installation-prerequisites)
*  [How to Install](#how-to-install)
*  [How to Run](#how-to-run)
*  [Attributes](#attributes)
*  [Examples](#examples)
*  [Additional Information](#additional-information)

## Overview

This pre-built allows IAP users to pass in an object and generate a JST that queries out individual items in the object which can then be used in IAP as a replacement for query tasks. 
At the time of publishing, only items in the first level of the object are exposed by the generated JST. 

## Installation Prerequisites
Users must satisfy the following prerequisites:
* Itential Automation Platform: `^2022.1`

## How to Install

To install the pre-built:
* Verify you are running a supported version of the Itential Automation Platform (IAP) as listed above in the [Prerequisites](#installation-prerequisites) section.
* The pre-built can be installed from within `App-Admin_Essential`. Simply search for the name of your desired pre-built and click the install button (as shown below).
<!-- REPLACE BELOW WITH IMAGE OF YOUR PUBLISHED ARTIFACT -->

<table><tr><td>
<img  src="./images/install.gif"  alt="install"  width="1000px">
</td></tr></table>

<!-- REPLACE ABOVE WITH IMAGE OF YOUR PUBLISHED ARTIFACT -->

  

## How to Run

Use the following to run the pre-built:

1. Once the pre-built is installed as outlined in the [How to Install](#how-to-install) section above, go to `Automation Catalog` and run the `Generate Query JST`  automation. In the `Enter name for the JST` field, enter the name for the generated JST and in the `Enter the Object`, enter the object for which you want to create the JST and click on `VIEW JOB`.

Here's an example for what a user might send in:
<table border='1' style='border-collapse:collapse'>
<tbody>
<tr>
<td><code>Enter name for the JST</code></td>
<td>testJST</td>
</tr>
<tr>
<td><code>Enter the Object</code></td>
<td><code>{
  "name": "John",
  "age": 23,
  "location": "Atlanta"
}
</code></td>
</tr>
</tbody>
</table>

<table><tr><td>
<img  src="./images/ac-item.gif"  alt="ac-item"  width="800px">
</td></tr></table>

2. In the job, click on the `WORK TASK` button that would have popped up, to view the generated JST and copy/save it to a file on your local system.
<table><tr><td>
<img  src="./images/run-job.gif"  alt="run-job"  width="800px">
</td></tr></table>
If imported into the JST designer, the JST will look like this:
<table><tr><td>
<img  src="./images/jst.png"  alt="jst"  width="600px">
</td></tr></table>

3. Now navigate to the workflow where you would like to query the items out of the object, add a `JSON Transformation` task and import the saved JST into IAP.
<table><tr><td>
<img  src="./images/import.gif"  alt="import"  width="800px">
</td></tr></table>

4. Each of the items in original object should be accessible in all of the subsequent tasks of the workflow
<table><tr><td>
<img  src="./images/tasks.gif"  alt="tasks"  width="800px">
</td></tr></table>

## Attributes  

Attributes for the pre-built are outlined in the following tables.

1. Input:
<table border='1' style='border-collapse:collapse'>
<thead>
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enter name for the JST</code></td>
<td>Enter the name that you want the generated JST to be called</td>
<td><code>string</code></td>
</tr>
<tr>
<td><code>Enter the Object</code></td>
<td>Enter the object for which you want to create the query JST</td>
<td><code>object</code></td>
</tr>
</tbody>
</table>


2. Output:
<table border='1' style='border-collapse:collapse'>
<thead>
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>createdJST</code></td>
<td>The generated query JST for the input object</td>
<td><code>object</code></td>
</tr>
</tbody>
</table>

## Examples
Examples describing how the pre-built will work for different inputs.

*Example 1*. Input: 
```
{
  "data": {
    "fruit": "apple",
    "price": "42.2",
    "type": "fruit"
  },
  "jstName": "details"
}
  ```

*Example 1*. Output (If imported into the JST designer, the JST will look like this):
<table><tr><td>
<img  src="./images/example1.png"  alt="example1"  width="600px">
</td></tr></table>
   <hr><br>
    

*Example 2*. Input - Showing support for only the first level of items: 
```
{
  "data": {
    "healthcheckVariables": {
      "numberOfRetries": 10,
      "numberOfRetriesStability": 10,
      "secondsBetweenRetry": 60
    },
    "mode": "Verbose",
    "iosDeviceHostname": "csr100v-03.10.03S",
    "release": "csr1000v-universalk9.03.10.03.S.153-3.S3-ext.SPA.bin"
  },
  "jstName": "device"
}
  ```

*Example 2*. Output (If imported into the JST designer, the JST will look like this):
<table><tr><td>
<img  src="./images/example2.png"  alt="example2"  width="600px">
</td></tr></table>
  
## Additional Information
Please use your Itential Customer Success account if you need support when using this Pre-Built Transformation.