in a SS2 user event script (before submit), when u...
# suitescript
f
in a SS2 user event script (before submit), when using var order = context.newRecord to load the current SO, is that dynamic mode? It seems to be standard, as I'm getting errors saying selectLine isn't found in the object: var orderLineNum = order.selectLine({ sublistId: 'item', line: i }); However, when I try to set a sublist value directly: order.setSublistText({ "sublistId": "item", "fieldId": "customscript_pref_bin_so", "line": i, "text": String(prefBinName) }); I get no errors but the custom column on the line isn't updated. Do I have to replace the context.newRecord with a normal call to open the transaction in dynamic mode?
s
is there a reason you have to use
selectLine
rather than just setting values directly?
c
its a standard mode N/record.Record reference not dynamic
you don't use selectLine with standard records, you juse use the get/set methods w/ the line specified
f
I'd be happy to just set the value directly. I tried using this: order.setSublistText({ "sublistId": "item", "fieldId": "customscript_pref_bin_so", "line": i, "text": String(prefBinName) }); but it fails silently.
makes me wonder if it's possible to edit sublist values in standard mode
c
Try setSublistValue instead of setSublistText
f
I did, it fails silently too
c
how are you getting the lines.. like whats your code to get the item sublist count? are other values populating and just not this field? is still value checked on the field?
f
field is free-form text with store value checked, and the field is editable within the form, and my client script did it no prob. the line loop is set up like this: var numLines = order.getLineCount({ sublistId : 'item' }); // to get sublist line number if (numLines > 0) { for (var i = 0; i < numLines; i++) {
also tried setting the value to a static chunk of text in case that was the problem, no difference
since it's a beforesubmit, I assume I don't have to save the record..
s
if that's a SalesOrder, I don't think it will have a field named
customscript_pref_bin_so
?
are you sure it isn't some other prefix you need (e.g.
custrecord_
?)
e
custcol
is likely if it's on a transaction sublist
f
I noticed that too...no idea how I got the wrong id in there. the right one is custcol_preferred_bin but it's still failing without an error
stripped down the whole script to as simple as possible... the custom column is still empty, but the cutsom body field gets updated fine: define(["N/record", "N/search"], function (r, search) { const trimLength = 32; var itemNames = []; function loadRecord(context) { log.debug({ title: 'SO concat startup. type: ', details: context.type }); var order = context.newRecord; order.setSublistValue({ "sublistId": "item", "fieldId": "custcol_preferred_bin", "line": 1, "text": "pref bin here" }); var bodyField = order.setValue({ fieldId: 'custbody_ref_skus', value: 'test text' }); } return { beforeSubmit: loadRecord }; });
ok, simply changing to setSublistText got it to work in the stripped version..could have sworn I tried that a bunch of times
j
when you do
setSublistValue
your function call needs to provide
value
property instead of
text
property
Copy code
setSublistValue({
  sublistId: 'item',
  line: 0,
  fieldId: 'your field',
  value: 'some value'
});
Copy code
setSublistText({
  sublistId: 'item',
  line: 0,
  fieldId: 'your field',
  text: 'some text'
});
I'll add that I almost never use or have needed to use setText or setSublistText
💯 1
f
Thanks, I did miss that when I tried setSublistValue
s
This is actually an example of why I use NFT - with NFT field would be defined once for the record type and only once, so getting it right once is all you need for 100 scripts that might use that field.
342 Views