I am trying to pass the null value to the lookup field using the Power Automate.
I am using the below expression.
I guess you are mixing up the different syntax of setting the null value.
For your case, you are using the / syntax. e.g.
/accounts/«GUIDValue»
If that is the case, your expression should be as follows without the bracket characters '(' or ')'
if(empty(triggerOutputs()?['body/_msi_backdonor_value']), '', concat('/accounts/', triggerOutputs()?['body/_msi_backdonor_value']))
I am not sure if that will work because I have never used that syntax to set the lookup value.
In my blog post, I am using the () syntax. e.g.
accounts(«GUIDValue»)
In that case, your expression should be as follows without the '/' character.
if(empty(triggerOutputs()?['body/_msi_backdonor_value']), '', concat('accounts(', triggerOutputs()?['body/_msi_backdonor_value'], ')'))
@LinnZawWin Hi Linn, I've used your expression, which works when you need to set NULL is the actual value being passed is null, but what if the value is NOT null - this expression does not set the value to the field.
If I use the standard of
If the Donor(Value) is null, this expression fails with the error: The supplied reference link -- -- is invalid. Expecting a reference link of the form /entityset(key) - therefore you need an expression that will pass NULL or pass the actual value in the field. The expression I am using is:
if(empty(triggerOutputs()?['body/_msi_backdonor_value']),'',concat('/accounts/(',triggerOutputs()?['body/_msi_backdonor_value'],')'))
It works in that if the field is NULL, nothing is added to Dataverse, but it also doesn't add a value if there is data.
Any ideas please? Many thanks, Lucia
Instead of an empty string, you can set a null value. Please refer to my blog post for more details.
https://linnzawwin.blogspot.com/2020/07/how-to-set-lookup-fields-with-null.html#updatenull
Here's the updated expression.
if(
not(empty(variables('varEvent'))),
concat
(
'hso_events(',
variables('varEvent'),
')'
),
null
)
Try using int('-1') inside your expression instead of '':
if(not(empty(variables('varEvent'))),concat('hso_events(',variables('varEvent'),')'),int('-1'))
Lookup fields are weird and the only way to clear them is to provide -1 as lookup ID. '' is just an empty string and won't be processed, so it will keep the current value.