Skip to main content
Nintex Community Menu Bar
Solved

In Form Variables, Get value from Collection data


Forum|alt.badge.img+2

There is a Collection variable at User Defined variables.

At form I want to get nth Index values of that collection.

It seems Form Functions does not have Get Item from collection nor similar functions.

 

Is there a way to get Collection value at form variables without using Get Item from Collection everytime?

 

Best answer by bsikes

@Juyoung 

You may be able to do this, but you need to be familiar with how regular expressions work. 

If I have a collection that contains the items Apple, Orange, and Cherry, I can use the form function Converttostring to have it return this: Apple,Orange,Cherry

 

I can then use the replace form function, to replace everything in that string except for the nth section. This would use a regular expression, and how that expression is written depends on the contents of your collection. The example below is the simplest example, and it assumes your collection is only made of strings and that no commas are in the collection (So that the only commas present are separating the items).

 

Collection Variable (TestC) items:

  • Apple
  • Orange
  • Cherry

 

Main Form Setup:

 

CollectionString Variable: 

convertToString([Workflow].[User defined variables].[TestC])

 

NthItem Variable: 

replace([Form].[CollectionString],"^([^\\,]*\\,){" + convertToString([Form].[NthIndex]) +"}([^\\,]*).*","$2")

 

Result on actual form:

 

 

It would be MUCH easier if there was a function to do this. 

View original
Translate
Did this topic help you find an answer to your question?

9 replies

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • July 12, 2023

Hi @Juyoung 

Is there a way to get Collection value at form variables without using Get Item from Collection every time?

Unfortunately No

 

 

 

Translate

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • July 12, 2023

If you need that feature, use the Nintex Ideas site to propose the feature.

https://ideas.nintex.com/ideas 

Translate

Forum|alt.badge.img+10
  • Scout
  • 129 replies
  • Answer
  • July 12, 2023

@Juyoung 

You may be able to do this, but you need to be familiar with how regular expressions work. 

If I have a collection that contains the items Apple, Orange, and Cherry, I can use the form function Converttostring to have it return this: Apple,Orange,Cherry

 

I can then use the replace form function, to replace everything in that string except for the nth section. This would use a regular expression, and how that expression is written depends on the contents of your collection. The example below is the simplest example, and it assumes your collection is only made of strings and that no commas are in the collection (So that the only commas present are separating the items).

 

Collection Variable (TestC) items:

  • Apple
  • Orange
  • Cherry

 

Main Form Setup:

 

CollectionString Variable: 

convertToString([Workflow].[User defined variables].[TestC])

 

NthItem Variable: 

replace([Form].[CollectionString],"^([^\\,]*\\,){" + convertToString([Form].[NthIndex]) +"}([^\\,]*).*","$2")

 

Result on actual form:

 

 

It would be MUCH easier if there was a function to do this. 

Translate

Forum|alt.badge.img+2
  • Author
  • Rookie
  • 5 replies
  • July 13, 2023

@bsikes  Thank you for the advice!

Unfortunately What we have to do is the opposite way(from NthIndex to NthItem)

But It would be a useful guide to achieve it.

I’ll search for breakthrough. I’ll update what I found.

Translate

Forum|alt.badge.img+2
  • Author
  • Rookie
  • 5 replies
  • July 13, 2023

@bsikes My apology I was looking at backward.

It was exactly what I need!

Sadly I already choose the answer so I cannot set it as the best answer.

 

also I add it at the idea

https://ideas.nintex.com/ideas/CNV-I-73

Translate

Forum|alt.badge.img+3
  • Rookie
  • 15 replies
  • December 17, 2024
Juyoung wrote:

@bsikes  Thank you for the advice!

Unfortunately What we have to do is the opposite way(from NthIndex to NthItem)

But It would be a useful guide to achieve it.

I’ll search for breakthrough. I’ll update what I found.

Hi

I’m trying to do something similar using a collection of object, I would like to retrieve a certain object based on one of its properties.

e.g.:

Collection is a collection of user. I have a drop down where I can pick a user. I want to retrieve the email of that user using a variable (I cannot use the value field of the drop down which is already used for something else). 

the data comes from a table (but that’s very relevant), right now the only way I can achieve this is by using a data variable everytime I need such a record. I can add the condition to that data variable to make sure I get the record I want. 

This is silly and not efficient since I’m reloading the data and doing lots of unecessary trips. 

 

Do you have a solution for this ? 

I’ve tried playing with the ConvertToString, but I basically need to search for a particular item in this and return the index, I could then use GetCollectionItem and everything would be perfect. 

Translate

Forum|alt.badge.img+10
  • Scout
  • 129 replies
  • December 17, 2024

@etienneg it depends completely on what your object looks like when converted to a string. 

 

Assuming you’re using a Nintex Table, that has the “_id” column and an “Email” column, I would guess you could follow this approach though:

  1. User selects choice from the dropdown, which stores the ID of the record chosen.
  2. Use a form variable with the replace function and the following components:
    1. Convert the table object to a string
    2. Regular expression that get’s everything up to the first instance of “_Id”:”TargetID”, then everything up to the first instance of “Email”:”, then capture everything not a quotation mark, then matches the quote and the rest of the string.
      1. Example: ".*\"_id\":\"" + [Form].[Choice  single 1] + "\".*?\"Email\":\"([^\"]*)\".*"
    3. What you want to replace everything that was matched with. In this case, you should be replacing the entire string with “$1”, which is the capture group in the regular expression above - the Email value. 
Translate

Forum|alt.badge.img+3
  • Rookie
  • 15 replies
  • December 17, 2024
bsikes wrote:

@etienneg it depends completely on what your object looks like when converted to a string. 

 

Assuming you’re using a Nintex Table, that has the “_id” column and an “Email” column, I would guess you could follow this approach though:

  1. User selects choice from the dropdown, which stores the ID of the record chosen.
  2. Use a form variable with the replace function and the following components:
    1. Convert the table object to a string
    2. Regular expression that get’s everything up to the first instance of “_Id”:”TargetID”, then everything up to the first instance of “Email”:”, then capture everything not a quotation mark, then matches the quote and the rest of the string.
      1. Example: ".*\"_id\":\"" + [Form].[Choice  single 1] + "\".*?\"Email\":\"([^\"]*)\".*"
    3. What you want to replace everything that was matched with. In this case, you should be replacing the entire string with “$1”, which is the capture group in the regular expression above - the Email value. 

Thanks for sharing, that’s a very creative solution which would work but it’s got a few drawbacks mainly it’s not friendly at all if any of the column changes… 

I’m going to try a different approach. 

I thought all I would need from Nintex is that instead of the “contains” function returning a boolean, if it was giving me the index of the matched item, I could then query the collection directly and get what I want. 

This gave me an idea, if I add an index column to my dataset (which happens to be a table), I can then use this as the value field in my drop down and get any property back by using something like

getCollectionItem([Table data].[MyTable].[Rows].[MyColumn],IndexValue)

I think that might work, drawback is obviously now I have to manage the said index to do that.

Really think they should implement something to get the index of the selected item in a drop down collection.

 

 

Translate

Forum|alt.badge.img+10
  • Scout
  • 129 replies
  • December 18, 2024

I think it would be fine if columns change - so long as your target column was named the same and the “_ID” column was always the first property of the record (I assume that’s the case?). That being said, I’ve not really used the tables at all, so I could be off base there. 

If you care to vote for it, I’ve previously submitted an idea that would also solve the issue: 

https://ideas.nintex.com/ideas/CNV-I-104

 

The Query JSON action in NAC is super helpful for filtering out a JSON object and returning the desired property. Unfortunately, it’s not available within the form side - only the workflow side. 

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings