0

I'm trying to work with the setProperty function in order to edit a JSON body during the execution of a flow, here is the expression:

setProperty(X, 'Y','bla bla 123456789' )

while

  • X is the json
  • Y the property i want to modify
  • 'bla bla 123456789' is the value

My question is: how can I replace '123456789' by a variable('ID') inside it, if I do the following thing

setProperty(X, 'Y','bla bla variable('ID')' )

It will take exactly what is written "variable('ID') and not the value of this variable !

any help ?

1 Answer 1

1

You have your variables('ID') within a string declaration so the variables object is not being accessed. You must concatenate the two separate strings ('bla bla' and variables('ID')); to do so, use the concat() function.

Your expression would look like this:

setProperty(X, 'Y', concat('bla bla ', variables('ID')))

If I am understanding the case you presented in the comments correctly, I believe you can still use the concat() function to accomplish this. You would need to concatenate the whole 'path' value with your variable ID.

The path value:

'/datasets/@{encodeURIComponent(encodeURIComponent(''.../sites/Support''))}/tables/@{encodeURIComponent(encodeURIComponent(''def533d7-8ede-4f29-b882-57d48a90c2d8''))}/onupdateditems'

would then become:

concat('/datasets/@{encodeURIComponent(encodeURIComponent(''.../sites/Support''))}/tables/@{encodeURIComponent(encodeURIComponent(''', variables('ID'), '''))}/onupdateditems')

Note that I am retaining the extra quotation marks to preserve the syntax of the original value.

The whole expression then becomes:

setProperty(body('Get_Flow')['properties']['definition'],'triggers', setProperty(body('Get_Flow')['properties']['definition']['triggers'], 'When_an_item_is_created_or_modified',setProperty(body('Get_Flow')['properties']['definition']['triggers']['When_an_item_is_created_or_modified'], 'inputs',setProperty(body('Get_Flow')['properties']['definition']['triggers']['When_an_item_is_created_or_modified']['inputs'], 'path',concat('/datasets/@{encodeURIComponent(encodeURIComponent(''.../sites/Support''))}/tables/@{encodeURIComponent(encodeURIComponent(''', variables('ID'), '''))}/onupdateditems')))))
4
  • I understand your proposition ! what about this difficult case: Commented Jan 9, 2020 at 0:25
  • powerusers.microsoft.com/t5/General-Power-Automate/… Commented Jan 9, 2020 at 0:26
  • and let me ask you, when i use concat() function you agree with me that the result is a string, how can i execute that customised funcion setProperty()? Commented Jan 9, 2020 at 0:39
  • 1
    @AIMENBOULAHIA Please see my modified answer. Commented Jan 9, 2020 at 15:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.