I am having a difficult time debugging this code… ...
# suitescript
d
I am having a difficult time debugging this code… if anyone can see how this is getting buggered up PLEASE LET ME KNOW as I have been at this one problem for 6 hours now
Copy code
function runDataExtraction(support_case, extraction) {
    var extraction_result = new Object();

    extraction_result.source = extraction.custrecord_mro_cm_dataextraction_source;
    extraction_result.varname = extraction.custrecord_mro_cm_dataextraction_varname;
    extraction_result.regex_string = extraction.custrecord_mro_cm_dataextraction_regex;
    extraction_result.primary_key = extraction.custrecord_mro_cm_dataexttraction_pk;
    extraction_result.record_type = extraction.custrecord_mro_cm_dataextraction_record;

    extraction_result.regex_modifier = (
      (extraction.custrecord_mro_cm_dataextraction_mod) ?
        extraction.custrecord_mro_cm_dataextraction_mod : ""
    );

    if(!extraction_result.regex_string){
      return extraction_result;
    }


    extraction_result.regex_string = "<%[0-9a-z]+%>";
    //extraction_result.regex_modifier
    log.debug({title: "Regex String: ", details: typeof extraction_result.regex_string});
    log.debug({title: "Regex Modifier: ", details: extraction_result.regex_modifier});

    var regex = new RegExp(extraction_result.regex_string,"g");
    var list_result = getListValue("customlist_mro_cm_dataextractiontype", extraction_result.source);
    log.debug({title: "Regex: ", details: regex});
    log.debug({title: "Source: ", details: extraction_result.source});
    log.debug({title: "Source Lookup: ", details: list_result.scriptid});

    var match_source = null;
    switch (list_result.scriptid) {
      case 'sender':  match_source = support_case.sender; break;
      case 'subject': match_source = support_case.subject; break;
      case 'message_content': match_source = support_case.content; break;
      case 'message_attachment_content': match_source = null; break; //Not yet implemented
      case 'message_attachment_name': match_source = null; break; //Not yet implemented
      default: break;
    }

    log.debug({title: "Match Source: ", details: match_source});
    if(match_source) {
      var result = match_source.match(regex);
      extraction_result.value = result;
      log.debug({title: "Extraction Result: ", details: result});

    }
    return extraction_result;
  }
The problem is around this variable
Copy code
extraction_result.regex_string = "<%[0-9a-z]+%>";
if I don’t hard code this and use the value coming from the record… the code doesnt work
Copy code
1	View	Field:	1/29/2020	1:04 am	272515 Default Anonymous Customer	companyid	Remove
2	View	Record Type:	1/29/2020	1:04 am	272515 Default Anonymous Customer	supportcase	Remove
3	View	Extraction Result:	1/29/2020	1:04 am	272515 Default Anonymous Customer	["<%sflkajd%>"]	Remove
4	View	Match Source:	1/29/2020	1:04 am	272515 Default Anonymous Customer	<%sflkajd%>	Remove

6	View	Source Lookup:	1/29/2020	1:04 am	272515 Default Anonymous Customer	subject	Remove
7	View	Source:	1/29/2020	1:04 am	272515 Default Anonymous Customer	2	Remove
8	View	Regex:	1/29/2020	1:04 am	272515 Default Anonymous Customer	 	Remove
9	View	Regex Modifier:	1/29/2020	1:04 am	272515 Default Anonymous Customer	g	Remove
10	View	Regex String:	1/29/2020	1:04 am	272515 Default Anonymous Customer	string
Here is the log output
if I use the value from the record the typeof output is still string
I am at a total loss
n
Hi @David Durst, is it possible for you to provide an example of what's in support_case and extraction? Would be easier to mock this, unless it's secret of course
d
suport_case is a supportcase record
extraction is just a POJSO (Plain Ole Javascript Object)
what you see in those varables its unloading is fairly straight forward
Did you need data details? @Nikola Gavric
n
I have a funny (aka bad/infuriating) feeling it's one of those "what the hell" moments where, despite it being a string you need to .toString() it or wrap it in double quotes.
d
BTDT
String() attempted
“” + attempted
just tried a .trim() also in that maybe some funky whitespace char is in there
n
Good to know. Clearly you've worked in NetSuite long enough to clutch at straws. 😉
d
I have been coding long enough to expect things to not work as documented
n
Was thinking the same as @Nelli, will try to run it here
d
my next guess is going to be attempting to copy the chars into a array and reconstruct the string by loop or something whacky like that
GRRRRRRR
FOUND IT!
n
Yeah? what was it? 😄
d
Copy code
9	View	Regex String Tester Length:	1/29/2020	1:27 am	272515 Default Anonymous Customer	13	Remove
10	View	Regex String Length:	1/29/2020	1:27 am	272515 Default Anonymous Customer	19	Remove
I just made that fixed string and compared lengths
the dynamic value is coming back at 19 length and the fixed is at 13 like it should be
n
Something being added to the dynamic one or why?
d
NS is adding something to it… somewhere….. but it doesn’t explain why my .trim() isn’t working
and now the mystery is psuedo solved…. but not sure how to prevent it welll.
Copy code
var regex_string_char_array = extraction_result.regex_string.split('');
["&","l","t",";","%","[","0","-","9","a","-","z","]","+","%","&","g","t",";"]
Its websafe’n the string
n
wow.. good job anyways 🙂
d
facepalm
crying sunglasses 1
p
Probably some UTF crappiness!
👍 1