Script to search for specific string in a a records field

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Script to search for specific string in a a records field

This topic contains 4 replies, has 2 voices, and was last updated by  Sam Moffatt 2 weeks, 1 day ago.

  • Author
    Posts
  • August 26, 2019 at 5:54 AM #36509

    matt coxon
    Participant

    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

    August 26, 2019 at 1:55 PM #36520

    Sam Moffatt
    Participant

    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

    August 31, 2019 at 4:07 AM #36642

    matt coxon
    Participant

    Thanks Sam , I hadn’t realised you had responded to this one as well I’ll try what you suggested
    Thanks
    Matt

    September 2, 2019 at 8:22 AM #36667

    matt coxon
    Participant

    perfect , thankyou Sam

    September 3, 2019 at 3:08 AM #36670

    Sam Moffatt
    Participant

    No worries, happy to help!

You must be logged in to reply to this topic.