- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 03:11 PM
SCENARIO:
Resource plan created, generating requested_allocations. resource_plan.planned_cost calculates correctly since its using the group_resource rate.
Because of the FiretrUCKING Labor Rate Card table swapping bug, hundreds of allocations have been created with the wrong resource_allocation.allocated_cost. That means resource_plan.allocated_cost is also borked.
Deconstructing the ResourcePlan script include I've found functions that allow me to recalculate planned cost, however no functions appear to recalculate and update a resource_allocation's allocated_cost, then recalculate the resource_plan.allocated_cost.
Anyone have any insights?
Here's a script I've been working with. updatePlanned() works, but updateAllocated() does nothing.
function updatePlanned(req) {
var resourcePlan = new ResourcePlan();
resourcePlan.get(req.getValue('resource_plan'));
resourcePlan.updatePlannedHoursAndCost(req.getTableName());
}
function updateAllocated(alloc){
gs.print('in updateAllocated');
var allocation = new ResourceAllocation(alloc);
allocation.calculateAllocatedCost();
var resourcePlan = new ResourcePlan();
//gs.print(alloc.getValue('resource_plan'));
resourcePlan.get(alloc.getValue('resource_plan'));
//resourcePlan.updateAllocatedCost();
resourcePlan.updateAllocatedHoursAndCost();
}
var rp = new GlideRecord('resource_plan');
rp.get('37313f471383e34084b3b7a66144b00c'); //my sample Resource Plan
gs.print(rp.short_description);
var rpreqs = new GlideRecord('requested_allocation');
rpreqs.addQuery('resource_plan',rp.sys_id);
rpreqs.query();
while (rpreqs.next()){
updatePlanned(rpreqs);
}
var rpallocs = new GlideRecord('resource_allocation');
rpallocs.addQuery('resource_plan',rp.sys_id);
rpallocs.query();
while (rpallocs.next()){
gs.print('Launch updateAllocated');
updateAllocated(rpallocs);
}
Solved! Go to Solution.
- Labels:
-
Resource Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 05:20 AM
Hi Robert,
Can you change the below function from
function updateAllocated(alloc){
gs.print('in updateAllocated');
var allocation = new ResourceAllocation(alloc);
allocation.calculateAllocatedCost();
var resourcePlan = new ResourcePlan();
//gs.print(alloc.getValue('resource_plan'));
resourcePlan.get(alloc.getValue('resource_plan'));
//resourcePlan.updateAllocatedCost();
resourcePlan.updateAllocatedHoursAndCost();
}
to
function updateAllocated(alloc){
var allocation = new ResourceAllocation(alloc);
allocation.updateAllocatedHoursAndCost();
var resourcePlan = new ResourcePlan();
resourcePlan.get(alloc.getValue('resource_plan'));
resourcePlan.updateAllocatedHoursAndCost();
}
and execute this. Try executing this in some temp instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 05:23 AM
Hey Harsha,
Isn't that the exact same code, just with the commented lines knocked out?
EDIT: Wait! Nope, I'm just blind. Thanks for the tip. I'll try this!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 05:26 AM
No. You are calling
allocation.calculateAllocatedCost();
If you see the actual code, it just sets allocated cost but doesn't update.
I am calling
allocation.updateAllocatedHoursAndCost();
which actually updates hours and costs as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 05:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 05:33 AM
So grateful for this, Harsha.
If you have the time, could you explain why its got to run ResourceAllocation.updateAllocationHoursAndCost as well as ResourcePlan.updateAllocatedHoursAndCost?