Forum Replies Created
-
AuthorPosts
-
Hi everyone,
I’ve created a user event script before load (on Task form) which should insert the sublist values for multiple fields (custom sublist child record) on the task form. Sources by the “Transaction” field.
I would like to know how I can loop through the lines on the sales order and then create these lines in the custom child record.
This is what I have – This is working. But im missing the loop function and I do now understand it.
Would be pleased if someone can help:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define([‘N/record’],
function(record) {
function beforeLoad(context) {
if (context.type !== context.UserEventType.CREATE)
return;
var newRecord = context.newRecord;
newRecord.setValue({
fieldId: ‘custevent27’,
value: ”
});
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id: context.newRecord.getValue({fieldId: ‘transaction’}),
isDynamic: true
});
var objSublist = objRecord.getSublist({
sublistId: ‘item’
});
var ObjField = objRecord.getSublistField({
sublistId: ‘item’,
fieldId: ‘custcol12’,
line: 0
});
var sublistFieldValue = objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘custcol12’,
line: 0
});
//SET Position#
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord251’,
line: 0,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘custcol12’,
line: 0})
});
//SET Item
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord252’,
line: 0,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘item’,
line: 0})
});
//SET Description
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord253’,
line: 0,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘description’,
line: 0})
});
//SET QUANTITY
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord257’,
line: 0,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘quantity’,
line: 0})
});
//SET INVENTORY DETAILS – not working till now
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord254’,
line: 0,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘inventorydetail’,
line: 0})
});
}
return {
beforeLoad: beforeLoad,
};
});
-
UPDATE:
Found the loop function.
But its only sourcing the first line – Not dynamically all other lines.
Currently im not able to use the function commit Line.ย (not available in standard record object)
Does someone know a way how to do it?/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define([‘N/record’],
function(record) {
function beforeLoad(context) {
if (context.type !== context.UserEventType.CREATE)
return;
var newRecord = context.newRecord;
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id: context.newRecord.getValue({fieldId: ‘transaction’}),
isDynamic: true
});
var objSublist = objRecord.getSublist({
sublistId: ‘item’
});
var numLines = objRecord.getLineCount({
sublistId: ‘item’
});
for (var line = 0; line < numLines.length; line++)
var objColumn = objSublist.getColumn({
fieldId: ‘item’
});
var ObjField = objRecord.getSublistField({
sublistId: ‘item’,
fieldId: ‘custcol12’,
line: line
});
var sublistFieldValue = objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘custcol12’,
line: line,
});
//SET Position#
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord251’,
line: line,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘custcol12’,
line: line})
});
//SET Item
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord252’,
line: line,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘item’,
line: line})
});
//SET Description
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord253’,
line: line,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘description’,
line: line})
});
//SET QUANTITY
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord257’,
line: line,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘quantity’,
line: line})
});
//SET INVENTORY DETAILS
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord254’,
line: line,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘inventorydetail’,
line: line})
});
//SET Condition
newRecord.setSublistValue({
sublistId: ‘recmachcustrecord250’,
fieldId: ‘custrecord255’,
line: line,
value: objRecord.getSublistValue({
sublistId: ‘item’,
fieldId: ‘custcol29’,
line: line})
});
}
return {
beforeLoad: beforeLoad,
};
});
-
-
AuthorPosts