Hey folks, What is the best way in a client script...
# suitescript
m
Hey folks, What is the best way in a client script to set a field on an item in the item sublist on a purchase order? What happens is the user enters a quantity and then selects an item. When the item is selected, several fields on the line item are populated. I am wanting to write a client script that populates a custom field when the item is selected. I started with something like this:
function fieldChanged(data) {
if (data.fieldId == "custcol_item_id") {
var line = data.line;
var val = 5;
data.currentRecord.selectLine({
sublistId: 'item',
line: line
});
data.currentRecord.setCurrentSublistValue({
sublistId: "item",
fieldId: "cust_integer_field",
value: val
});
data.currentRecord.commitLine({
sublistId:'item'
});
}
}
This actually works, but the
commitLine()
jumps to the next line of the sublist and throws an error that required fields are empty. If I remove the
commitLine()
, then the field I need set in the current/selected line doesn't actually set/populate Any ideas? Is fieldChanged the best entry point for this? Thank you!
b
probably best to only set the value of the current line that the user is currently setting
dont jump to other lines and commit them
m
right, I agree, that is what I am trying to do. When I wrote that it works, I meant it set the field value on the currently line, but then it jumps to the next line, which isn't desired @battk
b
dont select a select a line, dont commit a line
m
well, when I do that, it doesn't work at all.
For example, if I replace the code inside the if statement with this
var val = 5;
data.currentRecord.setCurrentSublistValue({
sublistId: "item",
fieldId: "cust_integer_field",
value: val
});
It doesn't set the field. That is what led me to trying to select and commit the line
s
If you want stuff to happen after item is selected and values are filled out, maybe try postSourcing
m
@Sandii Ah, thanks, I haven't ever used that entry point and just looked it up in the Help Center... I'll give that a try. The description there sounds like what I need.
this line in the docs is my only concern: "The event is not triggered by field changes for a field that does not have any slaved fields."
but I should have the slaved fields if I understand how all that is working
b
you would use postSourcing if the value you wrote is being overwritten. usually netsuite's ui isnt fast enough for you to not notice the field being set then unset
m
Well, neither way is working. The Post Source behaves exactly as the Field Changed did. Without selecting and committing the line, the field value won't set, but, if you commit the line that causes a lot of other problems.
b
id probably need to see more code, and potentially any field relationships between custcol_item_id and cust_integer_field