Hi, im playing around with scripts, (i’m new to them) is there a way to search a field for a partiular string and the output accordingly
Example would be
Field “Labels” has the following text (urgent,storage,emea,network,office moves,colo,new)
I’d like the script to search for the string “office moves” and return either a “yes” or whatever Id like
Is that possible
Thanks
Try something like this:
var address_id = 'fld-fb97220d3a4a4df48df4a54030766c54';
record.getFieldValue(address_id).match(/Cupertino/) ? 'Yes' : 'No';
You can use the method match
on strings, it takes a regular expression which is why the string is in backslashes not quotes. I use a ternary operator to take the output of the match and do a ‘yes’ or ‘no’ based on if something was found.
W3C Schools page for match: https://www.w3schools.com/jsref/jsref_match.asp (has links for further details on regular expressions)
Mozilla page on ternary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
Thanks Sam , I hadn’t realised you had responded to this one as well I’ll try what you suggested
Thanks
Matt
No worries, happy to help!