Elegant way for String interpolation

I’m wondering if there is any elegant way in the Snaplogic Expression Language to achieve String interpolation? E.g. similar to f-strings in Python?

f"This is a test string including a {variable}"

The method I’m using at the moment is string concatenation, e.g.:

"SELECT " + [lib.env.salesforceGPDeliveryNumberField,lib.env.salesforceGPOperationsNumberField,"Id"].toString() + " FROM Opportunity WHERE " + lib.env.salesforceOpportunityIdField + " = '" +  _opportunityId + "'"

This becomes fairly tedious with longer queries and prone to overlooking the one or other space or quote.
Concat might be a bit better than that, but still is somewhat tedious in comparison to string interpolation.
Is there a feature that I’ve overlooked or is there just no user-friendly method available?

Best regards

1 Like

Hey @Henchway,

Try adding a mapper in front of the SQL Execute, and map all of the configuration fields in there. Than you can simply use those fields in the query itself without using expressions. So you can understand me better, here’s your query transformed in the way I’m suggesting:

SELECT $salesforceGPDeliveryNumberField,$salesforceGPOperationsNumberField,Id FROM Opportunity WHERE $salesforceOpportunityIdField = $opportunityId


1 Like

Hi @Henchway,

You can also use the built-in function .sprintf().
For example, you could use the following expression:

"SELECT %s,%s,Id FROM Opportunity WHERE %s =\'%s\'".sprintf("one", "two", "someId", "123")

Which translates to:

SELECT one,two,Id FROM Opportunity WHERE someId ='123'

Thank you both, I’ll give both solutions a try once i’m back in the office.

Could you elaborate this one a bit?
When i specify this in a mapper beforehand, i could only do it in a non-expression field, therefore plaintext only. I’m putting this in a variable ‘query’, of course then it’s solely text.

When using this in a REST GET snap , it won’t evaluate the lib piece, but simply fail with http 400. I suppose the difference here could be that you’re strictly referring to a SQL Snap, but i’m sending the SQL statement via REST to Salesforce.

When activating the expression evaluation in the mapper, it fails as it won’t recognize e.g. ‘SELECT’ as a proper command.

Best regards