Skip to main content
Nintex Community Menu Bar
Question

Do UI only formulas support something like Case" in salesforce formulas?"

  • July 11, 2024
  • 8 replies
  • 20 views

Forum|alt.badge.img+17

I need look into a long text field and determine if a any words from a list are contained in the long text.  I can do this using a UI only formula field for one word, but what would be the best way to compare it to a list? Salesforce Formula fields have a “Case” function, but it can’t be used on Long Text Fields.  I don’t see a Case type of option in UI ONLY forumlas. Is it possible?

This topic has been closed for replies.

8 replies

Forum|alt.badge.img+7

At the risk of sending you down an arduous rabbit hole, have you considered using javascript’s RegEx?
RegEx expression (?:^|W)dog(?:$|W)|(?:^|W)brown(?:$|W) will match both dog and brown in “The quick brown fox jumped over the lazy dog”

You can play with it at: https://regex101.com/

Please note, I know next to nothing about regex, but use it after much trial and error on occasion.

https://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regu… has a snippet on one of the answers:

var myString = “something format_abc”;
var myRegexp = /(?:^|s)format_(.*?)(?:s|$)/g;
match = myRegexp.exec(myString);
while (match != null) {
// matched text: match[0]
// match start: match.index
// capturing group n: match[n]
console.log(match[0])
match = myRegexp.exec(myString); 
}
So your formula would be like (HAVE NOT TESTED IN SKUID AT ALL, and really guessing on actual syntax)

if(/(?:^|W)dog(?:$|W)|(?:^|W)brown(?:$|W)/.exec(string) !=null)  …

Presumably you’ll need to actually understand the regex, I just cribbed a sample and added an or (|) to handle multiple words, and you’ll probably want to use case insensitive


Forum|alt.badge.img+7

The alternative method i’d try is to split your search string into an array of words then search that. But it would probably require your formula field to call a function.



Forum|alt.badge.img+20

It’s called nested If in Skuid formula. 😉


Forum|alt.badge.img+18

You can also use skuid.formula.Formula() at add any formula you want to write in javascript to the skuid pagebuilder. Just use the javascript switch/case function.

I keep all my formulas on a single static resource added to my master page, like this:

&#47;&#47;Custom Formulas<br />(function (skuid){<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Shortcuts &amp; Global Variables &#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />var $ = skuid&#46;$;<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Formulas<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />var formulas = {<br />'REMOVE_TEXT': [<br />&nbsp; &nbsp; function (string_to_search, string_to_remove) {<br />&nbsp; &nbsp; &nbsp; &nbsp; return string_to_search&#46;split(string_to_remove)&#46;join(''); &nbsp; &nbsp; },<br />&nbsp; &nbsp; {numArgs: 2, returnType: 'text'}<br />]<br />};<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Register Formulas<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />$&#46;each(formulas,function(name,formulaArray){ skuid&#46;formula&#46;Formula(name, formulaArray[0], formulaArray[1]); });<br />})(skuid); 

Forum|alt.badge.img+17

Cool. Thanks, Matt!


Forum|alt.badge.img+13

Raymond, 

In Skuid’s Q4 release we are adding some new Formula Functions that should help with this: CONTAINS_ANY, CONTAINS_ALL, and CASE

CONTAINS_ANY will allow you to check whether a given input string contains any of a list of other strings, e.g.

CONTAINS_ANY({{Favorite_Food__c}}, “Spaetzle”, “Sauerkraut”, {{Dynamic_Food_Choice__c}})

CONTAINS_ALL() will allow you to check whether a given string contains ALL of a list of other strings.

And the CASE() statement is a convenience method to avoid a million nested IF() functions, e.g.

CASE({{Status}}, 0, “Open”, 1, “In Progress”, 2, “Closed”, “Invalid Status”)

to replace

IF({{Status}} == 0, “Open”, IF({{Status}} == 1, “In Progress”, IF({{Status}} == 3, “Closed”, “Invalid Status”)))


Forum|alt.badge.img+17

I just fainted! That is awesome. Thanks!


Forum|alt.badge.img+20

CAN’T WAIT FOR THE NEW RELEASE!!!