Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
heshkaru
Creator
Creator

TFileInputJson with condition

Is there a way to use conditions based on TFileInputJson and based on conditions pass json values to separate jobs.

Attached a pic

I need to pass json values based on condition to either in order 1 path or in order 2 path.

Labels (3)
1 Solution

Accepted Solutions
heshkaru
Creator
Creator
Author

Hi, I figure out the answer for this removing expected block.

 

0695b00000PMiY1AAL.pngThank you

View solution in original post

9 Replies
Anonymous
Not applicable

Hello,

To understand your requirement very well, could you please elaborate your case with an example with input and expected output values?

Best regards

Sabrina

heshkaru
Creator
Creator
Author

Im trying to figure out a way to use textractjson with a json object like below.

 

{

    "site_id": "003",

    "purchase_order_details": [

        {

            "item": "2285542",

            "purchase_order_details_notes": [

                {

                    "note_line": "1"

                }

            ]

        }

    ],

    "purchase_order_allowances": [

        {

            "amount": "23.5"

        },

        {

            "amount": "23.7"

        }

    ]

}

 

The issue was when using textractjson if one of the arrays in above obj "purchase_order_details" or "purchase_order_allowances" becomes null then the whole object becomes null when extracting.

 

So i need to check whether "purchase_order_details" and "purchase_order_allowances" arrays are not null and do the flow as in the picture.

If not if one of the array is null then to pass the information conditionally to another textractjsonfield component.

heshkaru
Creator
Creator
Author

@Xiaodi Shi​ @Shicong Hong​ Hi both,

 

0695b00000PMYkRAAX.png0695b00000PMYkbAAH.pngIf im using above json object and im getting the below log file.

 

My issue is if im using below json format(without the array)

 

0695b00000PMYklAAH.png0695b00000PMYkqAAH.pngIm not getting the result if the json array is null. How to handle this situation.

 

Thank you

Anonymous
Not applicable

Hi

If the file does not contain purchase_order_details item, means the array is null. My idea is to read the whole file content as a string using tFileInputRullRow, then check the string whether it contains "purchase_order_details" substring, set the result to a global variable (boolean type) which used to trigger different processing. eg:

tFileInputFullRow--main--tJavaRow--runIf1---tFileInputJson1....

--runIf2---tFileInputJson2....

on tJavaRow:

if(input_row.content.contains("purchase_order_details"){

globalMap.put("toRead_purchase_order_details", true);

}

 

set the conditon of runIf1 as:

(boolean)globalMap.get("toRead_purchase_order_details")

 

tFileInputJson1: read the json file with purchase_order_details array.

 

Can you try and let me know if you have any questions.

 

Regards

Shong

heshkaru
Creator
Creator
Author

Hi @Shicong Hong​ 

Thanks for the reply. I think this is not a good solution, cause there can be scenarios where "purchase_order_details" is mapped to null in json document. So in that case reading from the raw file is not a good solution. Anyhow thank you for the idea.

 

Thank you

Heshan

Anonymous
Not applicable

"purchase_order_details" node always exist in the file even though the value is null?

heshkaru
Creator
Creator
Author

If you dont have the node in the json is same as the node exist in the json with value as null. Both of those scenario can happen. Its because the json is so dynamic.

 

Thank you for the reply

heshkaru
Creator
Creator
Author

Hi @Shicong Hong​ , @Xiaodi Shi​ 

If I can do below then my task is also complete.

I have below complex input json.

/////////////////////////////////input///////////////////////////////

{

  "site_id": "003",

  "purchase_order_details": [

    {

      "item": "2285542",

      "purchase_order_details_notes": [

        {

          "note_line": "1"

        }

      ]

    }

  ],

  "expected": {

    "errorCode": "200"

  },

  "drop_ship_address": {

    "cust_order_no": "2377709"

  },

  "purchase_order_allowances": [

    {

      "amount": "23.5"

    }

  ]

}

/////////////////////////////////input///////////////////////////////

 

I need the below json format. Input may or maynot have "expected" block. But for the output json I need to omit "expected" block from the json

/////////////////////////////////output///////////////////////////////

{

 "site_id": "003",

 "purchase_order_details": [

  {

   "item": "2285542",

   "purchase_order_details_notes": [

    {

     "note_line": "1"

    }

   ]

  }

 ],

 "drop_ship_address": {

  "cust_order_no": "2377709"

 },

 "purchase_order_allowances": [

  {

   "amount": "23.5"

  }

 ]

}

/////////////////////////////////output///////////////////////////////

 

So far I have been using tJSONDocInput and tJSONDocOutput to figure out a solution.

 

Thank you

heshkaru
Creator
Creator
Author

Hi, I figure out the answer for this removing expected block.

 

0695b00000PMiY1AAL.pngThank you