Has anyone successfully created an Item Demand Pla...
# suitescript
r
Has anyone successfully created an Item Demand Plan via script? No matter what I try, I can’t seem to add more than 52 lines (weeks). Is there a gotcha that I’m not seeing? The transaction is supported via csv import so it must be possible somehow I would think. Any thoughts would be appreciated.
I keep getting an error that I am trying to edit a static sublist. I am setting the end date at the header level, which works in the UI.
b
what does your code look like
r
Here is my function. Found line is 48. This works until I get beyond line 52.
function createEditDemandPlan(itemObj){
try{
if(itemObj.demandPlan.length > 0){
record.delete({
type: record.Type.ITEM_DEMAND_PLAN,
id: itemObj.demandPlan
})
}
let demandPlan = record.create({
type: record.Type.ITEM_DEMAND_PLAN,
isDynamic: true,
});
demandPlan.setValue({fieldId: 'demandplancalendartype', value: 'WEEKLY' })
demandPlan.setValue({fieldId: 'subsidiary', value: 2})
demandPlan.setValue({fieldId: 'location', value: 16 })
demandPlan.setValue({fieldId: 'item', value: itemObj.item})
// demandPlan.setValue({fieldId: 'year', value: null});
// demandPlan.setValue({fieldId: 'month', value: null});
demandPlan.setValue({fieldId: 'startdate', value: formatDate('12/1/2023') })
demandPlan.setValue({fieldId: 'enddate', value: formatDate('12/31/2024') })
const id = demandPlan.save()
let loadedDemandPlan = record.load({
type: record.Type.ITEM_DEMAND_PLAN,
id: id,
isDynamic: false,
});
//demandPlan.setValue({fieldId: 'year', value: '2024'});
loadedDemandPlan.setValue({fieldId: 'startdate', value: '12/1/2023', forceSyncSourcing: true})
loadedDemandPlan.setValue({fieldId: 'enddate', value: '12/31/2024', forceSyncSourcing: true})
loadedDemandPlan.setValue({fieldId: 'demandplancalendartype', value: 'WEEKLY' })
// demandPlan.setValue({fieldId: 'startdate', value: null})
// demandPlan.setValue({fieldId: 'enddate', value: null})
// demandPlan.setValue({fieldId: 'year', value: null});
let currStart = loadedDemandPlan.getValue({fieldId: 'startdate'})
let currEnd = loadedDemandPlan.getValue({fieldId: 'enddate'})
log.debug('start and end before loop', currStart + '  ' + currEnd);
let detailLines = loadedDemandPlan.getLineCount({sublistId: 'demandplandetail'});
//let detailLines = 53;
log.debug('detailLInes', detailLines);
let startToPass = new Date('12/3/2023');
let endToPass = new Date('12/31/2024');
let sundaysCount = getFirstSundayDatesInRange(startToPass, endToPass)
log.debug('sunday count', sundaysCount.length);
let firstSunday = getFirstSundayOfMonth(startToPass)
let foundLine = loadedDemandPlan.findSublistLineWithValue({sublistId: 'demandplandetail', fieldId: 'startdate', value: formatDate(firstSunday)})
log.debug('foundline - 12/3/2023', foundLine);
for(let i = foundLine; i < foundLine + sundaysCount.length; i++){
log.debug('line index', i);
loadedDemandPlan.setSublistValue({sublistId: 'demandplandetail', fieldId: 'startdate', line: i, value: firstSunday})
loadedDemandPlan.setSublistValue({sublistId: 'demandplandetail', fieldId: 'quantity_1_', line: i, value: 99})
firstSunday = addDays(firstSunday, 7)
}
// loadedDemandPlan.commitLine({sublistId: 'demandplandetail'})
const id2 = loadedDemandPlan.save({enableSourcing: true})
}catch(e){
log.error('Caught Error', e.message);
log.error('Caught Error', e.stack);
}
}
I have tried dynamic mode and standard. standard seem to work better and at least let me set lines. Have tried insertLine, selectNewLine, etc. Everything I could think of.
b
go through Item Demand Plan
despite what the sample code shows, you want to use the matrix related apis to avoid the weird underscores in your code