I am using WebActivity to get QueueMessage from Azure Blob Storage and pass the output to ForEeach to use each QueueMessage in subsequent pipeline process.The pipeline is on schedule run and this is the Dynamic Expression I use in ForEach Items:
@json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage
It works fine when there are MessageText in the queue. But once the queue is cleared and the webactivity returns empty QueueMessageList as per below, the ForEach will start to fail
{
"Response": "<?xml version=\"1.0\" encoding=\"utf-8\"?><QueueMessagesList />",
"ADFWebActivityResponseHeaders": {
"Transfer-Encoding": "chunked",
"x-ms-request-id": "requestid",
"x-ms-version": "2020-04-08",
"Cache-Control": "no-cache",
"Date": "Tue, 13 Jun 2023 07:53:30 GMT",
"Server": "Windows-Azure-Queue/1.0;Microsoft-HTTPAPI/2.0",
"Content-Type": "application/xml"
},
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (Southeast Asia)",
"executionDuration": 0,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "ExternalActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}
ForEach Failure as follows:
The expression 'length(json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage)' cannot be evaluated because property 'QueueMessage' cannot be selected.
What is the correct way to check for the QueueMessageList before running ForEach. If the queue is empty, i would like to stop the ForEach without triggering any error.
Thank you.
To check if the
QueueMessagesListis empty before running theForEachactivity, you can use theiffunction to conditionally execute theForEachactivity only if theQueueMessagesListis not empty. Since theForEachactivity cannot be used directly inside anIf Conditionactivity, you can design a two level pipeline by using the combination ofIf ConditionandExecute Pipelineactivities to achieve the requirement. In outer pipeline take the web activity and if activity. Inside if activity take the execute pipeline activity.Outer Pipeline:
This expression will return
trueif theQueueMessagesListproperty contains one or moreQueueMessageelements, andfalseif theQueueMessagesListproperty is empty. that is, it does not contain anyQueueMessageelements.This expression returns
trueif there are messages in theQueueMessagesListproperty, andfalseif there are no messages.Inner Pipeline:
This way, you can execute the
ForEachactivity only if theQueueMessagesListis not empty.