I have a custom sublist in a transaction that has ...
# suitescript
p
I have a custom sublist in a transaction that has a parent/child relationship with a custom record. Users are able to add a record in the transaction via the Add button. In the record I have a field that has a formula which takes 3 of the other fields and multiplies them. This works fine when I add the record and the calculated field shows in the sublist in view mode but in edit mode of the transaction the field does not show because the value is not being stored (which makes sense). I created a script to have the value of another field = the value of the field with the formula. It works in the custom record if I add a record that way but if I add a record in the transaction the field does not populate. I deployed the same script to the transaction but get a NaN message in console. So question is - how can I script for the math to take place when the record is added in the transaction?
b
which one of the 4 types of sublists are you working with. A sublist created from a parent/child relationship can be a different type depending on the record mode, so you may need to detail what it is in view and edit mode
you probably also want to share the script
p
I believe it is an inline editor sublist because once I add the line in the sublist it shows in the record. I changed my script to do the same math that the formula does and that works on the record level but not in the transaction:
define(['N/record','N/search','N/ui/dialog', 'N/log'], function (record, search, dialog, log) {
/**
*@NApiVersion 2.0
*@NScriptType ClientScript
*/
function fieldChanged(context) {
var currentRecord = context.currentRecord;
if(currentRecord.fieldId = "custrecord_my_dims_height") {
var length = currentRecord.getValue({
fieldId: 'custrecord_my_dims_length'
});
console.log(length);
var width = currentRecord.getValue({
fieldId: 'custrecord_my_dim_width'
});
console.log(width);
var height = currentRecord.getValue({
fieldId: 'custrecord_my_dims_height'
});
console.log(height);
var ltlvolcalc = length * width * height;
console.log(ltlvolcalc);
if (height > 1) {
currentRecord.setValue({
fieldId: 'custrecord_my_dims_ltl_cw',
value: length * width * height,
ignoreFieldChange:true
});
}
}}
return {
fieldChanged: fieldChanged
}});
b
read the docs and figure out which
one of them doesnt support suitescript and you dont want to be wasting your time working with an incompatible sublist
p
Inline editor is definitely my sublist type.
b
and what does the code for your transaction look like
p
I actually tried the same code which I am pretty sure is not the right way to go. Looking more into the sublists api to learn some more.
b
that would be the correct path, sublists have their own methods
you probably want to start with a more standard sublist like an item sublist, then move onto Custom Child Record Sublist Creation with SuiteScript