Search in a array values from Script output

Alekya Seemakurty, Sri 86 Reputation points
2023-07-17T17:00:08.32+00:00

Hello,

I have output from a script activity as below :

LookupBusinessDays:

output

{
    "resultSetCount": 1,
    "recordsAffected": 11,
    "resultSets": [
        {
            "rowCount": 11,
            "rows": [
                {
                    " OUTPUT_DAYS": "2023-07-10"
                },
                {
                    " OUTPUT_DAYS": "2023-07-11"
                },
                {
                    " OUTPUT_DAYS": "2023-07-12"
                },
                {
                    " OUTPUT_DAYS": "2023-07-13"
                },
                {
                    " OUTPUT_DAYS": "2023-07-14"
                },
                {
                    " OUTPUT_DAYS": "2023-07-17"
                },
                {
                    " OUTPUT_DAYS": "2023-07-18"
                },
                {
                    " OUTPUT_DAYS": "2023-07-19"
                },
                {
                    " OUTPUT_DAYS": "2023-07-20"
                },
                {
                    " OUTPUT_DAYS": "2023-07-21"
                },
                {
                    " OUTPUT_DAYS": "2023-07-24"
                }
            ]
        }
    ]
}

I have to check another variable value : PipelineDate ='2023-03-01' exists in above array or not.

I tried contains but it is not working.

Here is my simple pipeline: All I have to do is, check for the variable TriggerDate(output of Set PipelineTriggerDate : 2023-07-17) is within the output of Business days from theLookup activity.

User's image

  • ConcatPipelineDate Output:

Code : @concat('"DATE":',variables('PipelineTriggerDate')) - However concat is adding additional forward slash as below.

User's image

  • CheckPipelineDate output:

Code : @contains(activity('LkpBusinessDays').output.value,
concat('"DATE":',variables('PipelineTriggerDate')) )

User's image

Concat is adding a additional forward Slash. Or is there a better way to search the days from the array of values?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2023-07-18T11:32:40.09+00:00

    Hi Alekya Seemakurty, Sri ,

    Welcome to Microsoft Q&A platform and thanks for raising your question here.

    As per my understanding, you are trying to validate if the output of a variable is present in the list of items of array coming out of the script activity or not. Kindly let me know if my understanding is incorrect.

    You need to convert the output of script activity into array instead of array of json i.e. :

    {
                        " OUTPUT_DAYS": "2023-07-13"
                    },
                    {
                        " OUTPUT_DAYS": "2023-07-14"
                    }
    

    needs to be converted to ["2023-07-13","2023-07-14"]

    Also, the set variable activityconcat pipeline dateis not needed if you try the following solution.

    Please try the below approach and see if it helps:

    • Create another variable say appendedvar with array datatype.

    User's image

    • After script activity, use a foreach activity and set the sequential option as true. Provide this expression in Items of Foreach:
    @activity('Script1').output.resultSets[0].rows
    
    • Inside foreach, use append variable activity , and provide this expression in value: @item().OUTPUT_DAYS
    • Now, outside foreach , use the set variable activity to validate the presence of variable output in the appendedvariable array using this exp:
    @contains(variables('appendvar'),variables('PipelineTriggerDate'))
    
    
    

    Hope it helps. Kindly accept the answer if it's helpful. Thankyou

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Vahid Ghafarpour 23,385 Reputation points Volunteer Moderator
    2023-07-17T19:01:30.1333333+00:00

    Did you try json function?

    @contains(json(activity('LookupBusinessDays').output.resultsSets[0].rows), concat('{"OUTPUT_DAYS": "', variable('PipelineDate'), '"}'))
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.