Ivan
03/01/2018, 1:15 PMIvan
03/01/2018, 1:16 PMfunction saveRecord(scriptContext) {
var rec = scriptContext.currentRecord;
var itemLineCount = rec.getLineCount({
sublistId: "item"
});
if (itemLineCount > 0) {
for (var lineNum = 0; lineNum < itemLineCount; lineNum++) {
//selecting lines in the Item Receipt
rec.selectLine({
sublistId: "item",
line: lineNum
});
//check if line has subrecord
if (!rec.hasCurrentSublistSubrecord({
sublistId: "item",
fieldId: "inventorydetail"
})) {
continue;
}
//get Inventory Detail form with target value (Bin)
var invDetDyn = rec.getCurrentSublistSubrecord({
sublistId: "item",
fieldId: "inventorydetail"
});
//iterating through lines in Inventory detail
var lineInInvDet = 0;
while (true) {
/* Impossible to get number of lines on the subrecord. Possible reason is that the currentRecord is in the dynamic mode
* try...catch used for catching cases, when we considered every line. Non existing line throws an error.
*/
try {
invDetDyn.selectLine({
sublistId: "inventoryassignment",
line: lineInInvDet
});
} catch (error) {
//no more lines in the Inventory Detail form
break;
}
// getting bin value with no problems
var binValue = invDetDyn.getCurrentSublistValue({
sublistId: "inventoryassignment",
fieldId: "binnumber"
});
var binField = invDetDyn.getSublistField({
sublistId: "inventoryassignment",
fieldId: "binnumber",
line: lineInInvDet
});
// inside the console log I can see the field, but most
// of it's values are undefined.
//the most interesting for me is the getSelectOptions,
// which should allow me to get all options
console.log(binField);
lineInInvDet++;
}
}
}
return true;
}