Expand my Community achievements bar.

Got questions about Workfront Governance? Join our upcoming Ask Me Anything session on February 12th!
SOLVED

Fusion: How to Get an Object Value if Key has Periods in it?

Avatar

Level 2

Hello everyone -

 

I'm trying to use the "get (object; path)" function to get field values out of the parameterValues object.

 

I set a variable such as MY-VARIABLE to have the name of the field I want such as:  "DE:My Field Name Here"

 

Then I get the field value using "get" as follows:  {{get(`1.body.data.parameterValues; MY-VARIABLE)}}

 

This works great if the field name has no periods.  But if the field name has periods, such as "DE:My.Field.Name.Here", it always returns empty (apparently it's conflicting with the dot-notation used in "get").

 

So, my question:  is there a way to deal with periods in the key name within "get" above?

 

Or, alternately:  is there a way to parameterize the field name within field mapping syntax, i.e. to use a variable such as MY-VARIABLE instead of a literal field name, such as:

 

{{1.body.data.parameterValues.`DE:My.Field.Name.Here`}}  =>  {{1.body.data.parameterValues.MY-FIELD-VARIABLE}}

 

Something tells me I'm missing something really obvious here.... any ideas, anyone?

 

Thank you in advance!

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hello Sven-IX -

 

Well, I was able to do it in a roundabout way, but at least in a way that doesn't require replacing period characters.

Here's what I did::

Step 1:  I set a variable named "My-Field-Name-Variable" that contains the name of the field that has periods in it, e.g. I set the variable to be something like:  DE:Field.Name.With.Periods.In.It

Step 2:  Then later in the scenario I get the value of that field using the formula as shown in the screenshot below. 

Basically, I rely on the "pick" function instead of "get", since "pick" seems to work with field names with periods in it (since it's not trying to trace an object path like the "get" function does). 

It works as follows:

Pick:  look to parameterValues (which is retrieved earlier in the scenario using a GET API call to get object information) and return a collection for the key i.e. field name in my variable (i.e. this returns a collection containing the field I'm looking for, where the key of that collection is the field's name and the value is the field's value)

ToArray:  convert that collection to an array.  This array will have 1 element, and that element will be a collection containing the field I want

Map:  extract the value from that collection for the same key i.e. field name the variable.  This returns an array of 1 element, where the element is the value of the field I want.

Get:  extract element 1 from the array (the one and only element).  This (finally) returns the value of the field name I wanted. 

Of course, this approach works for any field name in the variable, whether the field name has periods or not, so I don't have to do a different approach (i.e. the regular "get" function") for field names without periods vs. the approach above for field names with periods.  I can just use this approach consistently across the board.

 

FranciscoRuiz_0-1732561762585.png

 

Anyway, if anyone knows of a better way, I'd certainly appreciate hearing about it!  

And, thank you again, Sven-IX. 

Cheers.

View solution in original post

3 Replies

Avatar

Level 6

Hi @FranciscoRuiz 

It's doable but it's ugly. In short: Don't use field names that contain periods....

Due to the limited tools available in Fusion, if you want to access a property on an object you'll need to 

  1. convert the collection to a JSON string
  2. replace the keys so they don't contain a period
  3. convert back to an object

attached my blueprint. 

 

Avatar

Correct answer by
Level 2

Hello Sven-IX -

 

Well, I was able to do it in a roundabout way, but at least in a way that doesn't require replacing period characters.

Here's what I did::

Step 1:  I set a variable named "My-Field-Name-Variable" that contains the name of the field that has periods in it, e.g. I set the variable to be something like:  DE:Field.Name.With.Periods.In.It

Step 2:  Then later in the scenario I get the value of that field using the formula as shown in the screenshot below. 

Basically, I rely on the "pick" function instead of "get", since "pick" seems to work with field names with periods in it (since it's not trying to trace an object path like the "get" function does). 

It works as follows:

Pick:  look to parameterValues (which is retrieved earlier in the scenario using a GET API call to get object information) and return a collection for the key i.e. field name in my variable (i.e. this returns a collection containing the field I'm looking for, where the key of that collection is the field's name and the value is the field's value)

ToArray:  convert that collection to an array.  This array will have 1 element, and that element will be a collection containing the field I want

Map:  extract the value from that collection for the same key i.e. field name the variable.  This returns an array of 1 element, where the element is the value of the field I want.

Get:  extract element 1 from the array (the one and only element).  This (finally) returns the value of the field name I wanted. 

Of course, this approach works for any field name in the variable, whether the field name has periods or not, so I don't have to do a different approach (i.e. the regular "get" function") for field names without periods vs. the approach above for field names with periods.  I can just use this approach consistently across the board.

 

FranciscoRuiz_0-1732561762585.png

 

Anyway, if anyone knows of a better way, I'd certainly appreciate hearing about it!  

And, thank you again, Sven-IX. 

Cheers.

Avatar

Level 6

Lol MAP!! Brilliant - I guess it was too late for me last night  

My only thought is that if you modify the object like I described, you do it once, and then reference any property downstream.
But if your solution works - awesome. Much more elegant than my ugliness.