function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ChopkinsChopkins 

Using a variable in a Data Source Advanced Script

It is my plan to create a custom button that will launch a flow and pass the AccountID through on the query string.  The AccountID will be assigned to a variable called v_AccountIDFull.

 

I then want to display a dynamic choice to the user of all contacts for that account that meet certain criteria.  The list should be sorted.

 

So to get started, I defined a datasource with this script that has the AccountID value hard-coded in it:

 

SELECT Id, LastName,Name from Contact 
WHERE (AccountID='XXXXX' AND CONTACT_TYPE__C INCLUDES ('Support'))
ORDER BY LastName

 

Works wonderfully.  However, I now want to reference my v_AccountIDFull variable in that script.

 

To clarify:

 

1) I cannot use the Choice Lookup filter to do this because I would have to have selected the AccountID from the Contact record in the query above.  If I include the AccountID in the SELECT query above I get no results from the dataset.

2) I cannot just use the standard "select the table with the data" option because if I do that I cannot use the INCLUDES statement above to filter out records that have a specific value in a multi-picklist.

 

  • I select the "Dynamic Script" button.
  • I see the top pane that says "Elements which can be used in your advanced script."  In that list is my v_AccountIDFUll variable.
  • I see the bottom pane which has my Advanced Script with the query above.
  • What is the syntax in the Advanced Script pane to reference the v_AccountIDFull variable value?

Double-clicking the element in the top pane does nothing.  If I change the script to this:

SELECT Id, LastName,Name from Contact 
WHERE (AccountID=v_AccountIDFull AND CONTACT_TYPE__C INCLUDES ('Support'))
ORDER BY LastName

 

I OK that value and then try to hit Next and I get an Advanced Script Validation error:

 

Data source, ds_Contacts Script was provided
None, WHERE (AccountID=v_AccountIDFull AND CONTACT_TYPE__C ^ ERROR at Row:2:Column:17 unexpected token: 'v_AccountIDFUll' (There was a problem executing your command).

 

If I change it to have a colon in front to signify a variable:

 

SELECT Id, LastName,Name from Contact 
WHERE (AccountID=:v_AccountIDFull AND CONTACT_TYPE__C INCLUDES ('Support'))
ORDER BY LastName

 

I get another validation error:

Data source, ds_Contacts Script was provided
None, WHERE (AccountID=v_AccountIDFull AND CONTACT_TYPE__C ^ ERROR at Row:2:Column:17 unexpected token: ':' (Bind variables only allowed in Apex code)  (There was a problem executing your command).

 

If anyone can help me I would really appreciate it....

 

Chopkins