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])
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])
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.
@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:
User selects choice from the dropdown, which stores the ID of the record chosen.
Use a form variable with the replace function and the following components:
Convert the table object to a string
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.
Example: ".*\"_id\":\"" + [Form].[Choice single 1] + "\".*?\"Email\":\"([^\"]*)\".*"
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.
@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:
User selects choice from the dropdown, which stores the ID of the record chosen.
Use a form variable with the replace function and the following components:
Convert the table object to a string
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.
Example: ".*\"_id\":\"" + [Form].[Choice single 1] + "\".*?\"Email\":\"([^\"]*)\".*"
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
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:
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.
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.