whats the best way to compare strings and verify t...
# suitescript
n
whats the best way to compare strings and verify they are the same? (script or saved search) I have a map/reduce right now where I am using "NOT LIKE" in a CASE WHEN statement as a pre-filter of sorts but it does not seem to be working that well (I am comparing a custom item description text box on a work order with the memo field on the line of the related sales order)
c
try the equalto
n
in the sql of the saved search or in the script?
I have a feeling comparing a text area vs a text column field (memo) on the line item is messing things up
using the "like" comparator seems to work to a certain degree... but lots of results are not matching when they clearly should be
I'm checking the length of both strings and some have different lengths... so its not matching
but I tried putting both in a character counter and they are the same... not sure what is happening here
g
any carriage returns? length doesn’t mean the same thing in all contexts. sometimes it’s characters and sometimes it’s bytes. you mentioned text area — carriage returns could get stripped out of a regular text field and kept in a textarea.
n
Yeah its multi line
that must be it
any ideas on how to compare properly?
g
any comparison is going to be kind of expensive cuz you’re gonna have to convert the textarea. But i guess you’re already down the road. it could be a simple as as
REPLACE
on all
\n
in the description and then comparing.
n
@Gerald Gillespie so what I ended up doing is exactly that, using REPLACE for tabs, spaces, carriage returns, etc. and got it to work
🙌 1
g
@screnshaw ping you here just cuz you said
suck at regex
which is the same thing (to me) as saying i need to be better at regex cuz writing code and sucking at regex are insympatico… and this is a nice easy example to get your feet wet what @Nicolas Bean could do here (and maybe did) is use
REGEX_REPLACE
. something like this in a filter or where clause or join condition
Copy code
REGEX_REPLACE( textareaField, '\W','') = REGEX_REPLACE(textField, '\W','')
whether using saved search or suiteQL you can still test it fairly easily using SuiteQL. something like this:
Copy code
select str ,
 REGEXP_REPLACE( source.str, patterns.removeallwhitespace, ''),
 REGEXP_REPLACE( source.str, patterns.justspaces, '')

 from
 (select 
 'first line
second line
tab	between
3spaces  between
last line'
as str )  source   join 

(select '\W' as removeallwhitespace, ' ' justspaces  ) patterns on 1=1
if you are using an external regex tester make sure it has an option for Oracle’s POSIX Support. ( If you are pulling out the value and doing in suitescript then you want ecmascript support comparable to the suitescript version you’re using)
118 Views