Reputation: 1923
I have a for each activity which has a stored procedure (SP) wherein I am inputing values using item() evidently.
Now suppose SP's input values are item().a, item().b and item().c
Question: For some of the iteration of foreach, item().b does not exist which is expected. So how should i deal with it in the Stored procedure? Because at this point of time it is giving me an error when it executed SP by saying:
"The template language expression 'item().b' cannot be evaluated because property 'b' doesn't exist, available properties are 'a, c'
or how should I overcome this failure in the data factory?
Apparently, data factory has the check for empty() but it does not have the check for exist().
Upvotes: 5
Views: 9163
Reputation: 2363
You could use “?”. I.e., item()?.b
Please reference question mark and a related post.
Upvotes: 11
Reputation: 815
I don't think you can solve this in the Data Factory. You could use the String(Item()) to convert it to a Json string in the format:
{
'a':'value',
'b':'value',
'c':'value'
}
Then you can handle that in your stored procedure with some creative SQL:
DECLARE @jsonParams NVARCHAR(255) = '
{
"a":"a value",
"c":"b value"
}'
DECLARE @paramA VARCHAR(10) = (SELECT JSON_VALUE(@jsonParams,'$.a'))
DECLARE @paramB VARCHAR(10) = (SELECT JSON_VALUE(@jsonParams,'$.b'))
DECLARE @paramC VARCHAR(10) = (SELECT JSON_VALUE(@jsonParams,'$.c'))
Upvotes: 1