would anyone know if it's possible to assign a fie...
# suitescript
u
would anyone know if it's possible to assign a field value to a Custom Field of the List/Record type? for context, I'm currently trying to use
record.setValue()
to assign a value to a Custom Field that's sourcing from a Custom List with three entries (which have ID values of 1,2, and 3 respectively). as mentioned trying to assign a value with
record.setValue()
doesn't seem to work. I figured it would be an issue with the value I'm assigning, but assigning the text nor the ID value works. I'm not sure if this is a limitation of the function, or maybe I'm missing something?
c
How does it not work? Are you getting an error? What kind of script? Can you share code?
☝️ 1
u
currently, my code is within a SS2 Suitelet that handles GET and POST. on POST, I parse the received data
params
through a function
part1
and plug them in a Custom Record's form
newRec
in Netsuite. For the specific field, I created a similar drop-down list on the HTML form with three options, all `name`'d and `id`'d with 1a, 1b, and 1c respectively, while in Netsuite is a Custom List with three entries with the ID's 1,2, and 3.
Copy code
function part1(ob, opt) {
   let a = ''
   for(let x = 0; x < opt.length; x++) {
     if(opt[x] in ob) {
       a = opt[x].toString();
       break;
     }
   }
   return a;
}

//...

let _07_choices = ["1a", "1b" ,"1c"];
let _07_promptness = part1(params, _07_choices);

newRec.setValue({ 
   fieldId: "custrecord_idaud_promptness", 
   value: _07_choices.indexOf(_07_promptness) + 1].toString()
});
As shown, I attempt to return a number in string format, to no avail. Trying to return it formatted as an int or float doesn't seem to work either, as I keep getting the error:
You have entered an Invalid Field Value -1 for the following field: custrecord_idaud_promptness
I'm not sure where I'm lost or what I'm missing tbh *edit, typo
b
three problems
your lookup fails giving you a -1 index
it was doomed in the first place since the index has no relation to the value you need to set
you want to use the internal id of the select option as the value, not whatever indexing strategy you have going on
start more simple, hardcode the internal id before trying to write a lookup
d
If you
let _07_choices = {"1a": 1, "1b": 2, "1c": 2};
then the setValue piece becomes
newRec.setValue({
fieldId: "custrecord_idaud_promptness",
value: _07_choices[param]
});
interested to know if that bypasses the problematic bits