/**
* Function used to create BOM revision
* @param dataObj
* @param integrationRecObj
* @param componentData
* @param bomRecId
* @returns {boolean}
*/
bomRevisionCreation(dataObj, integrationRecObj, componentData, bomRecId) {
try {
let bomRevisionRec = record.create({
type: record.Type.BOM_REVISION,
isDynamic: true
});
// NAME
bomRevisionRec.setValue({
fieldId: 'name',
value: dataObj.Number + ' rev' + dataObj.Revision
});
let dateToday = savedSearch.getDateToday();
// EFFECTIVE START DATE
bomRevisionRec.setValue({
fieldId: 'effectivestartdate',
value: dateToday
});
bomRevisionRec.setValue({
fieldId: 'billofmaterials',
value: bomRecId
});
let isRevIncomplete = false;
for (let i = 0; i < componentData.length; i++) {
try {
let componentItem = savedSearch.itemSearch(componentData[i].PartNumber);
if (jjUtil.checkForParameter(componentItem)) {
bomRevisionRec.selectNewLine({sublistId: 'component'});
bomRevisionRec.setCurrentSublistValue({
sublistId: 'component',
fieldId: 'item',
value: componentItem
});
bomRevisionRec.setCurrentSublistValue({
sublistId: 'component',
fieldId: 'bomquantity',
value: Number(componentData[i].PartUse.Quantity)
});
bomRevisionRec.commitLine({sublistId: 'component'});
} else {
isRevIncomplete = true;
}
} catch (e) {
log.error({
title: e.name,
details: e
});
}
}
let bomRevisionId = bomRevisionRec.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
if (bomRevisionId) {
let submitValues;
if (!isRevIncomplete) {
submitValues = {
[windchillLibrary.FLD_BOM_REVISION]: bomRevisionId,
[windchillLibrary.FLD_INTEGRATION_SUCCESS]: true,
[windchillLibrary.FLD_BOM_REVISION_ERR]: ""
}
} else {
submitValues = {
[windchillLibrary.FLD_BOM_REVISION]: bomRevisionId,
[windchillLibrary.FLD_BOM_REVISION_ERR]: 'Some items are not available to add to the BOM revision.',
[windchillLibrary.FLD_INTEGRATION_SUCCESS]: false
}
}
record.submitFields({
type: windchillLibrary.REC_WINDCHILL_INFO,
id: integrationRecObj.integrationRecId,
values: submitValues
});
}
} catch (e) {
log.error(e);
}
},