azure-data-factory

If condition in set variable is throwing an error azure data factory


I am extracting href from a link to get the url for pagination, i am storing an api response in blob as json. Using lookup activity i am reading the json and set a variable for next pagination url. The below logic is working fine when file has a pagination and url is in a link array. But when there is no pagination url present in a file then link is not an array and i am getting this error

expression cannot be evaluated because property 1 cannot be selected object. properties can only be selected by names

Logic

@if(
equals (activity('LookupActivity').output. firstRow[ 'feed']
['link '][1]['@rel'], 'next'),
activity('LookupActivity').output.firstRow['feed ']['link'][1]
'@href'],
ā€˜ā€™
)

Pagination-

enter image description here

No pagination

enter image description here

I am using this variable in until activity and iterating through other pages.


Solution

  • enter image description here

    You are receiving the above error when there is no pagination. It's because in this case, the link key value is a JSON object unlike an array in the case of pagination.

    So, first check whether the link value is object or an array and then check your condition. Modify your expression like below.

    @if(
        and(and(contains(string(activity('Lookup1').output.firstRow['feed']['link']),'['),greaterOrEquals(length(activity('Lookup1').output.firstRow['feed']['link']),1)),equals(activity('Lookup1').output.firstRow['feed']['link'][1]['@rel'], 'next')),activity('Lookup1').output.firstRow['feed']['link'][1]['@href'],''
    )
    

    enter image description here

    Now, it will give expected results in both cases of pagination and no pagination.

    Result with Pagination:

    enter image description here

    Result when there is no Pagination:

    enter image description here