Nairolf
09/23/2023, 2:45 AMAnthony OConnor
09/23/2023, 3:35 AMNairolf
09/23/2023, 11:19 AMNairolf
09/23/2023, 1:12 PMfunction pageInit(scriptContext) {
log.debug('scriptContext', scriptContext.mode);
if (['copy'].indexOf(scriptContext.mode) < 0) {
return null;
}
// let rec = scriptContext.currentRecord;
let rec = cr.get();
let transformFrom = rec.getValue({
fieldId: 'transform'
})
log.debug({
title: 'transformFrom',
details: transformFrom
})
if (['opprtnty'].indexOf(transformFrom) < 0) {
return null;
}
let itemSublist = rec.getLineCount({
sublistId: 'item'
})
log.debug({
title: 'itemSublist',
details: itemSublist
})
rec.cancelLine({
sublistId: 'item'
})
for (let i = 0; i < itemSublist; i++) {
rec.selectLine({
sublistId: 'item',
line: i
})
rec.cancelLine({
sublistId: 'item'
})
const currentPriceLevel = rec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'price',
// line: i
});
const currentRate = parseFloat(rec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
// line: i
}));
log.debug({
title: 'currentPriceLevel & rate',
details: currentPriceLevel + ' | ' + currentRate
})
// rec.selectLine({
// sublistId: 'item',
// line: i
// })
console.log(i);
// rec.selectLine({
// sublistId: 'item',
// line: i
// })
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_acs_opp_rate',
value: currentRate,
ignoreFieldChange: false,
// forceSyncSourcing: false
})
if (currentPriceLevel < 0) {
console.log('custom');
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: '10.00', //parseFloat(currentRate),
ignoreFieldChange: false,
// forceSyncSourcing: true
})
} else {
console.log('not custom');
// rec.setCurrentSublistValue({
// sublistId: 'item',
// fieldId: 'price',
// value: '-1',
// // line: i,
// // ignoreFieldChange: true,
// // forceSyncSourcing: true
// })
// rec.setCurrentSublistValue({
// sublistId: 'item',
// fieldId: 'rate',
// value: parseFloat(currentRate),
// // line: i,
// // ignoreFieldChange: true,
// // forceSyncSourcing: true
// })
// rec.commitLine({
// sublistId: 'item',
// ignoreRecalc: true
// })
// rec.selectLine({
// sublistId: 'item',
// line: i
// })
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'price',
value: currentPriceLevel,
ignoreFieldChange: false,
fireSlavingSync: true
})
}
rec.commitLine({
sublistId: 'item',
ignoreRecalc: false
})
}
}
battk
09/23/2023, 2:40 PMbattk
09/23/2023, 2:41 PMNairolf
09/23/2023, 3:49 PMbattk
09/23/2023, 3:50 PMNairolf
09/23/2023, 3:52 PMNairolf
09/23/2023, 8:39 PMNairolf
09/23/2023, 8:41 PMAnthony OConnor
09/23/2023, 9:41 PMcr.get()
instead of the commented out out scriptContext.currentRecord
? I think both should be fine, but I'd always use the scriptContext one.
2. why do you mix log.debug and console.log? I always just use console.log in client scripts, again this isn't an issue and its supposed to work to show logs on script records I think? I just never switched.
3. what IS and ISNT logging, the code is only half the story we need to see what's happening at run time.
4. Why do you select and then cancel lines? I don't think I've seen that pattern before, I don't know that its doing anything bad but it just looks strange.Nairolf
09/23/2023, 11:00 PMscript Context.currentRecord
2. Because I was tired to always go back to the NetSuite log 😉 and it’s eventually easier in the console.
3. the list on item price level is not updated and the custom column is not as well. I.e. all set…Value don’t work
4. I explained in my post earlier. I tried to do that since I kept having a dialog box saying « please choose an item… »
NB: this code is ugly because I’ve tried a zillion things to get this thing working in vain…battk
09/23/2023, 11:13 PMrec.selectLine({
sublistId: "item",
line: i,
});
rec.cancelLine({
sublistId: "item",
});
const currentPriceLevel = rec.getCurrentSublistValue({
sublistId: "item",
fieldId: "price",
});
const currentRate = parseFloat(
rec.getCurrentSublistValue({
sublistId: "item",
fieldId: "rate",
}),
);
if you dont know, you can check in the ui yourself, cancelLine is equivalent to clicking the cancel button
same as selectLine is equivalent to clicking a sublist lineNairolf
09/24/2023, 12:23 AMbattk
09/24/2023, 12:34 AMbattk
09/24/2023, 12:34 AMbattk
09/24/2023, 12:35 AMNairolf
09/24/2023, 12:38 AMbattk
09/24/2023, 12:38 AMNairolf
09/24/2023, 12:43 AMfunction pageInit(scriptContext) {
log.debug('scriptContext', scriptContext.mode);
if (['copy'].indexOf(scriptContext.mode) < 0) {
return null;
}
let rec = scriptContext.currentRecord;
let transformFrom = rec.getValue({
fieldId: 'transform'
})
log.debug({
title: 'transformFrom',
details: transformFrom
})
if (['opprtnty'].indexOf(transformFrom) < 0) {
return null;
}
let itemSublist = rec.getLineCount({
sublistId: 'item'
})
log.debug({
title: 'itemSublist',
details: itemSublist
})
for (let i = 0; i < itemSublist; i++) {
const currentPriceLevel = rec.getSublistValue({
sublistId: 'item',
fieldId: 'price',
line: i
});
const currentRate = parseFloat(rec.getSublistValue({
sublistId: 'item',
fieldId: 'rate',
line: i
}));
log.debug({
title: 'currentPriceLevel & rate',
details: currentPriceLevel + ' | ' + currentRate
})
}
}
Nairolf
09/24/2023, 12:43 AMbattk
09/24/2023, 12:44 AMNairolf
09/24/2023, 12:55 AM