Pass Records to Flow Record Collection Variable

I’m launching a Salesforce flow with a Skuid button, and I’d like to be able to pass all records in a model into a Record Collection variable. Is there a way to do this? I can see how to pass a single record using a merge variable, but not sure whether there is merge syntax to pass all records in a model.

Hey @Elissa_Bradley and welcome back!

If you would like to pass all records to the model, you could do something like:
{{$Model.modelName.data}}

Be sure to replace modelName with your actual model name.

You can find more info:
https://docs.skuid.com/latest/v2/en/skuid/merge-syntax/global-merge-variables.html#id2

Thank you! It’s good to be back.

Just tried that syntax, but I’m getting an error in the Chrome console that I can’t interpret. I am on an old version of Skuid (12.2.9)… maybe I should upgrade before I try to track this down.

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Array'
    |     index 0 -> object with constructor 'Object'
    |     property '__skuid_record__' -> object with constructor 'Le'
    |     property '_model' -> object with constructor 'Ue'
    --- property 'data' closes the circle 

No prob @Elissa_Bradley !

Hmmm looking at the error, can you verify how you are passing the data? it seems to be a mismatch in the data type( array → object).

One solution you can try to do is loop through the rows and merge each value in a comma-separated list like so(see example):

{{#$Model.Accounts.data}}'{{Id}}'{{^Record.isLast}},{{/Record.isLast}}{{/$Model.Accounts.data}}

More information can be found in the doc:
https://docs.skuid.com/latest/v2/en/skuid/merge-syntax/#looping-over-arrays

I am using a Record Collection Variable in my flow (which is looking for Case records to be passed in), and was trying to use this merge syntax to pass in records: {{$Model.SelectedCases.data}}.

I tried creating a Collection Variable instead of a Record Collection Variable in my flow, but trying to populate that using the same merge syntax ({{$Model.SelectedCases.data}}) resulted in the same error.

I did try out the latest merge syntax you provided – {{#$Model.SelectedCases.data}}{{Id}}{{^Record.isLast}},{{/Record.isLast}}{{/$Model.SelectedCases.data}} – and I can use that to populate the Collection Variable, but that syntax puts a comma after the last record in the list, like this:

CasesToCoverArray = [5000h00001lN4l6AAC,5000h00001lN4l6AAC,]

If I take out the comma in the merge syntax and test with a single record, I’m successful. So - any idea why the output has that final comma??

Hey @Elissa_Bradley , here is a solution that should work:

  1. Create on UiOnly formula field (call it something like IDListCommas ) with the merge that adds the trailing comma: {{#$Model.SelectedCases.data}}{{Id}},{{/$Model.SelectedCases.data}}
  2. Create a second UiOnly formula field (call is something like IDList ) that references the first field, but trims the trailing comma: LEFT({{IDListCommas}},LEN({{IDListCommas}}-1))

Splitting it into two different formulas cuts down on evaluations (i.e. you only have do loop over the data and build the string of IDs once)

Thanks for sticking with me on this @anon57098112! (And - appreciate that this cuts down on evaluations; that’s the whole reason I’m passing the data to a flow… was having issues with volume using a snippet and think I can simplify in a flow…if I can pass in a collection!)

So - I’m still getting a weird error. I added the UI-only fields to the SelectedCases model but get this: 1. Syntax error in formula field “IDListCommas” at line 1, column 3: Expected [ \x0C\n\r\t\x0B - ] but “#” found…

I also tried creating a UI-Only model to hold these fields, but that results in the same error.

thoughts?

Hey @Elissa_Bradley and no worries!

Can you share your Model XML that contains the formulas so we can take a look and see what is happening?

Thnaks.

Here’s the model:

	<model id="SelectedCases" limit="50" query="false" createrowifnonefound="false" sobject="Case" datasource="salesforce">
		<fields>
			<field id="Subject"/>
			<field id="Id"/>
			<field id="IDListCommas" uionly="true" displaytype="FORMULA" length="255" label="IDListCommas" ogdisplaytype="TEXT" readonly="true" returntype="TEXT">
				<formula>{{#$Model.SelectedCases.data}}{{Id}},{{/$Model.SelectedCases.data}}</formula>
			</field>
			<field id="IDList" uionly="true" displaytype="FORMULA" length="255" label="IDList" ogdisplaytype="TEXT" readonly="true" returntype="TEXT">
				<formula>LEFT({{IDListCommas}},LEN({{IDListCommas}}-1))</formula>
			</field>
		</fields>
		<conditions/>
		<actions/>
	</model>

@anon57098112 , coming back to this again… any ideas on my XML?

Hi @Elissa_Bradley,
I think I may have a solution for you. Unfortunately, the “truthy/falsy” merge syntax (#$Model…,^$Model… and /$Model…) that allows you to loop through the rows in a model is not supported in UI only field formulas which is why you are getting the syntax error. Good news though - I think the original merge syntax you were trying can be updated to leave out the final comma.

Something like this should do the trick:

  • Add a UI-only field to your Selected Cases model called something like “isLast”. Make it a formula field that results in a checkbox with the formula value {{Record.isLast}}
  • Then reference that UI-only field in your merge syntax logic to leave out the last comma in the list: {{#$Model.SelectedCases.data}}'{{Id}}'{{^isLast}},{{/isLast}}{{/$Model.SelectedCases.data}}

That should give you a comma separated list (without the final comma) to use for your collection variable.

Hi Elena,
Thank you for this! I played around with your syntax, then realized I could pass a text string into my flow and parse out the IDs (and remove the final semi-colon) in the flow, which ended up working better for me because I couldn’t figure out how to get my flow to handle the collection variable. I had an easier time passing in a text string.

Now I have a question about the {{$Model.SelectedCases.data}} syntax. I have a table on the screen where users can select rows. On the table I have an action “adopt rows into model” / “rows in context” into a new model - my SelectedCases model. Then, I show a pop-up that is designed to show the user what she’s selected. The table shows the selected cases nicely.

The issue is that the merge syntax is passing the first of the selected ID multiple times (one time for each item I selected.) I know this because I’m stamping the user record with output value of the merge syntax, just to understand what is happening. So, if I pick three cases, the first of which has ID 5005C000007LvjeQAC, the following is passed via the merge syntax:

5005C000007LvjeQAC;5005C000007LvjeQAC;5005C000007LvjeQAC;

This is the merge syntax that i’m using:

{{#$Model.SelectedCases.data}}{{Id}}{{/$Model.SelectedCases.data}}

Any ideas what might be going on here?

I did notice that if I used this merge syntax in a rich text field and used “SelectedCases” as my context model and checked “do not run template on each row”, the output value looked correct.

Hi Elissa,

Glad that helped!

It looks like the merge syntax that is used to iterate over each row gives unexpected results (showing data from the first row for every row) when it is run from a component that references the same model that you are looping through in the merge syntax. So if you’re triggering the flow and passing in merge syntax from a button, try updating the model on the button set component to a model other than SelectedCases, or even leave it blank and that should do the trick.

Elena, thanks again!

I changed the model (on a Page Title Component, which is where my button is displayed) to an unrelated model. But now the merge syntax is sending a row from the unrelated model - the first row for every row selected! It seems that the merge syntax is referencing the underlying model and grabbing the first row, one time for each selected row.
Very strange!! Bug?

And - I figured it out! I needed to put the button in a Button Set - not a page title - and that did the trick. For others trying to pass multiple records into a flow variable:

I am using a button on a button set to launch a Salesforce action.
My variable is a text variable that I’m parsing within my flow.
Merge syntax for my text variable: {{#$Model.SelectedCases.data}}{{Id}};{{/$Model.SelectedCases.data}}

Awesome! Glad to hear you got it working.