I've tried as both an array of values and as a str...
# suitescript
g
I've tried as both an array of values and as a stringified array of values and neither works 😞
a
The array of values must be an array of internal IDs, it will replace the current selection, so if you want to append you need to read and build the array with current selection + your new selection.
g
typeof and getValue of "writer"
object ["4","337"]
I then use:
Copy code
record.submitFields({
              type: "customrecord_gmr_subcontract",
              id: subcontractId,
              values: {
                custrecord_subcon_primary: true,
                custrecord_subcon_royaltyid: writer
              }
            });
But the field doesn't update
custrecord_subcon_royaltyid is a multiple select field of the same list/record as the writer field with the same filters so I know these are valid values
a
Try with the ID as integer, not strings.
g
ok GPT is suggesting writer.join() so I'm testing that now, assuming that fails I'll turn them into ints
In my mind join shouldn't work
a
Most likely the integer thing.
g
but suitescript can be odd
join did not work, of course, trying int
int is also not working
I've verified that both the source field and the target field are the same list (locations) and both multiple select and both values selected are available to be selected on the target record.
Copy code
// Writer field is a multiple select of locations returning an array of IDs
          let writer = context.newRecord.getValue({ fieldId: "custrecord149" })
            .map(id => parseInt(id, 10));

          log.debug("Writer", writer);

          record.submitFields({
            type: "customrecord_gmr_subcontract",
            id: subcontractId,
            values: {
              custrecord_subcon_primary: subcontractId === primarySubcontract && primary,
              custrecord_subcon_royaltyid: writer
            }
          });
Log output:
[4,337]
the "primary" checkbox updates as expected, but the multiple select royalty id field does not.
a
Do you have any filtering or permissions in that field?
g
checking
I already changed it from inline to normal just in case
Actually before checking, I switched to a different field that is ALSO a multiple select of locations used for a different purpose (I did NOT do this implementation haha) and it updated just fine so it's definitely the royalty ID field that's the problem
got it. Store value is not checked.
It was originally a single select sourced from the other record
but when I switched to multiple select it broke the sourcing
so I decided to script it
didn't remember it wasn't storing value
a
NetSuite custom records behave weird sometimes, your best bet will be to delete the field and create it again... ideally with a different ID.
g
Testing it after checking the store value box
works 🙂
👍 1
Thanks for the brainstorming. Sometimes you just need a second pair of eyes to stop banging your head against the wall
headbang 1
👍 1
Same problem now from the other direction. Yesterday I was copying the value from the parent record, when saving it, to all of its children. Today I'm adding logic to the child record to pull the value from its parent when saving.
Copy code
// [NET-428] Set the value of Royalty ID to the value of parent Contract "Writer" field (custrecord149)
      const contractId = context.newRecord.getValue({ fieldId: "custrecord_subcon_contract" });
      if (contractId) {
        const contractFields = search.lookupFields({
          type: "customrecord_nsacs_contract",
          id: contractId,
          columns: ["custrecord149"]
        });
        const royaltyIds = contractFields.custrecord149.map((royalty) => parseInt(royalty.value, 10));
        log.debug("Royalty IDs", royaltyIds);
        context.newRecord.setValue({ fieldId: "custrecord_subcon_royalty_id", value: royaltyIds });
      }
But it doesn't set the value.
in the log it shows up as an array of integers.
[4,23,337]
I know it's not the form this time because it's the same form as yesterday
and I already fixed it yesterday
From the documentation: options.value number | Date | string | array | boolean The value type must correspond to the field type being set. For example: Multi-Select fields accept arrays of string or number values.
Resurfacing this in the channel in case no one's looking at yesterday.
a
is it the same field as yesterday?
cos you were calling it
custrecord_subcon_royaltyid
yesterday, and today its
custrecord_subcon_royalty_id
the problem isn't with your array, that looks fine
g
oh gosh, typos
Well that's embarrassing.
Thank you!!
a
lol it happens to us all 🙂