The \u0005 piece is an unescape character.
# suitescript
k
The \u0005 piece is an unescape character.
n
probably a pipe sign or a comma. Which is okay. He will need to basically either loop through each and push it into an array and assign that array.
Confirmed it's a pipe sign '|'
k
That's odd though.
Think he will just need to unescape the string.
n
Not actually. The multi-select getValue return values separatd by pipe-sign. But you can't use it in setValue.
I would still prefer looping through and pushing into a array and assigning it. If he unescapes, he will probably need to replace the pipe-sign with comma. Not sure though.
k
should be able to do that with a .replace after unescaping.
n
@Gustavo Doná Hope you followed our convo
k
Copy code
var value = record.getValue({fieldId: 'multiselectfield'});
var unescapedvalue = decodeURI(value);
var setvalue = unescapedvalue.replace('|',',');
record.setValue({fieldId: 'multiselectfieldnew', value: setvalue});
I think that is about right from memory.
n
The replace here is not working. I just tested in console. Seems strange to me.
var a = unescape("4\u00053"); var b = a.replace("|", ","); console.log(b); Both a & b here give "4|3"
g
@karlenigma I tried to use your code, but it returned the value "[Ljava.lang.String;@ba035c3"
k
may be due to the fact that the character is escaped in the string being passed. Just checking regexp.
.replace(/\|/g, ',')
Try that instead.
n
This is what will work: var value = record.getValue({fieldId: 'multiselectfield'}); var newvalue = value.split('\u0005'); record.setValue({fieldId: 'multiselectfieldnew', value: newValue});
*newvalue with a small 'v' in last line.
k
either will work.
j
When dealing with multiselects I tend to use @Nik’s method as I believe you have to set them as an array.
g
I tried Nik's and got the error: Java class "[Ljava.lang.String;" has no public instance field or method named "split".
k
.split is standard JS.
n
You need to do a to String before split in that case.
toString()
g
When I use toString() the array turns into this string "[Ljava.lang.String;@60ef2818"
k
can you send over your full code?
g
var employees=config.getValue({fieldId:'custrecord_employee'}); employees=employees.toString(); var employeesArr=employees.split('\u0005'); record.setValue('employeefield',employeesArr);
k
Copy code
var employees=config.getValue({fieldId:'custrecord_employee'});
        var employeesStr=employees.toString();
        var employeesArr=employeesStr.split('\u0005');
        record.setValue('employeefield',employeesArr);
g
thanks hahah
When I use toString() I should get "4,3" or "4|3", and not "[Ljava.lang.String;@60ef2818" though
k
i have just tried
Copy code
var employees='4\u00053';
var employeesStr=employees.toString();
var employeesArr=employeesStr.split('\u0005');
console.log('employeefield ' + employeesArr);
in the console and all works ok.
is this in a UE or Client?
g
UE
MU actually
k
MassUpdate script
g
Yes
But the employees variable gets an array from the multiselect field
var employees=array ✔️ var employees='4\u00053'; string 🚫
netsuite 1
k
Copy code
var employees=config.getValue({fieldId:'custrecord_employee'});
        log.debug({title: 'config employees', details: employees});
        var employeesStr=employees.toString();
        log.debug({title: 'employeesStr', details: employeesStr});
        var employeesArr=employeesStr.split('\u0005');
        log.debug('employeefield',employeesArr);
run this and let me know what the log values are.
✔️ 1
g
employeesStr=[Ljava.lang.String;@1ecdd058
employees=["4","3"]
employeesArr= //error Java class "[Ljava.lang.String;" has no public instance field or method named "split".
k
if you are getting ["4","3"] from the first log then this is the string you need to set to the array.
there is no pipe character.
g
But if I try to use setValue with this employees array I get the error: "You have entered an Invalid Field Value 4\u00053"
k
I believe it is because the values are stringified.
g
I tried this
var employees=config.getValue({fieldId:'custrecord_updp_audemployee'});
log.debug({title: 'employees', details: employees});
var employeesArr=[];
for (var p=0;p<employees.length;p++){
employeesArr.push(parseInt(employees[p]))
}
log.debug({title: 'employeesArr', details: employeesArr});
Same error You have entered an Invalid Field Value 4\u00053
k
That doesnt make any sense.
g
In this case I got the employeesArr with number values
Indeed, my friend
k
@Nik anything to add to this? seems mighty odd.
I just tried
Copy code
var employees=["4","3"];
log.debug({title: 'employees', details: employees});
var employeesArr=[];
for (var p=0;p<employees.length;p++){
    employeesArr.push(parseInt(employees[p]))
}
log.debug({title: 'employeesArr', details: employeesArr});
in the debugger and had no problems at all.
g
when I declare a variable and set the values I have no problem as well
The problem is when you get that string from a multiselect field
When you get that array from a multiselect field *
k
but if your log is stating that is the array is ["4","3"] then you have an issue using the code you gave.
What is the field you are trying to set the values to? is it also a multiselect fiedl?
with the same list/record?
✔️ 1
@Gustavo Doná i'm lost with this TBH. there should be no issues in my opinion.
g
That's correct, it is from one multiselect to another
Both multiselects have the same values
Maybe it is some problem regarding NetSuite, I will open a case there. I will let you know. It makes no sense
Really appreciate your help
🙏 1
c
I don't see any issue with the JS itself. I prefer the ES6 unicode representation of
\u{xxxx}
instead, but that does us no good here. https://flaviocopes.com/javascript-unicode/
n
I will work on a solution in my system and get back soon. The key here will be the typeOf value we get from the multiselect. I will do some homework and share my findings. I remember I have done this in past.
@Gustavo Doná did try to do this on my own. The thing is it never showed any sort of escaped sequences. This is something very specific to your case or so it seems to me. The multi-select you are getting your values from, is bound by what? Like a customlist/child records or something else?
🙏 1
g
Really appreciate your help @Nik. I could finally transfer the values. This is what I did: var jsonFile=JSON.parse(JSON.stringify(record)); var employees=jsonFile.fields.multiselectfield1; otherrecord.setValue('multiselectfield2',employees);
n
I like the way you did it. 👍🏻 for you.