The CostPlanBatchOperations script include provides methods that enable the creation of a large number of cost plan records for demands and projects using batch processing. Use this script include instead of GlideRecord to more efficiently create multiple cost plan records.

Use the CostPlanBatchOperations.add() method to add any number of cost plans to a batch queue. Once you have added all the required cost plans, use the CostPlanBatchOperations.process() method to create/insert the cost plans in your instance. Until you call the CostPlanBatchOperations.process() method, the add requests remain in the batch queue (they are not yet added to your instance). If for some reason you need to remove all of the cost plans in the batch queue, use the CostPlanBatchOperations.clear() method.

To use this script include you must activate the PPM Standard (com.snc.financial_planning_pmo) plugin.

CostPlanBatchOperations - add(Object costPlan)

Adds one or more cost plans to a specified task (project or demand). Use this method when you want to create multiple cost plans.

Once processed, the cost plans are inserted into the specified project or demand. You can then view and modify them within your instance. For additional information, see Create a project cost plan and Create a demand cost plan.
Note: This method only defines the cost plans to add to your instance. The cost plans are not inserted into your instance until the costPlanBatchOperations.process() is called.
Table 2. Returns
Type Description
void

Example

This example shows how to add a simple batched cost plan.

//Define Array of Cost Plan records in JSON format
var costPlanRecords= [];
costPlanRecords.push({
   name:'Capital Expense',
   task:'f7a36d1bdb58001025c85a35dc96193a', // sys_id of the task
   unit_cost:1000.00, //decimal 
   resource_type:'a546eaf79330120064f572edb67ffb70', // sys_id of the cost type definition
   start_fiscal_period:'091b6e60cb111200f2de77a4634c9c2e', // sys_id of the start fiscal period record 
   end_fiscal_period:'0d1b6e60cb111200f2de77a4634c9c2f',// sys_id of the end fiscal period record 
   quantity:1 // Optional cost plan record attributes
});
 
var costPlanBatchOperations = new CostPlanBatchOperations();
costPlanBatchOperations.add(costPlanRecords);
var costPlanSysIds = costPlanBatchOperations.process();

CostPlanBatchOperations - clear()

Removes all cost plan objects that were added using the CostPlanBatchOperations.add() method.

Note: This method only works for cost plans that have been added. Once a cost plan is processed, this method cannot remove it. Processed cost plans must be removed manually through the UI.
Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
void

Example

This example shows how to clear the batch queue after adding cost plans.

//Define Array of Cost Plan records in JSON format
var costPlanRecords= [];
costPlanRecords.push({
   name:'Capital Expense',
   task:'f7a36d1bdb58001025c85a35dc96193a', // sys_id of the task
   unit_cost:1000.00, //decimal 
   resource_type:'a546eaf79330120064f572edb67ffb70', // sys_id of the cost type definition
   start_fiscal_period:'091b6e60cb111200f2de77a4634c9c2e', // sys_id of the start fiscal period record 
   end_fiscal_period:'0d1b6e60cb111200f2de77a4634c9c2f',// sys_id of the end fiscal period record 
   quantity:1 // Optional cost plan record attributes
});
 
var costPlanBatchOperations = new CostPlanBatchOperations();
costPlanBatchOperations.add(costPlanRecords);
var costPlanSysIds = costPlanBatchOperations.process();
costPlanBatchOperations.clear();

CostPlanBatchOperations - process()

Processes all of the cost plans that were added using the CostPlanBatchOperations.add() method and creates corresponding cost plans and relevant rollups.

Once the cost plans are successfully processed, the cost plan queue is cleared.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
Array Sys ID for each generated cost plan.

Example

This example shows how to process a simple batched cost plan.

//Define Array of Cost Plan records in JSON format
var costPlanRecords= [];
costPlanRecords.push({
   name:'Capital Expense',
   task:'f7a36d1bdb58001025c85a35dc96193a', // sys_id of the task
   unit_cost:1000.00, //decimal 
   resource_type:'a546eaf79330120064f572edb67ffb70', // sys_id of the cost type definition
   start_fiscal_period:'091b6e60cb111200f2de77a4634c9c2e', // sys_id of the start fiscal period record 
   end_fiscal_period:'0d1b6e60cb111200f2de77a4634c9c2f',// sys_id of the end fiscal period record 
   quantity:1 // Optional cost plan record attributes
});
 
var costPlanBatchOperations = new CostPlanBatchOperations();
costPlanBatchOperations.add(costPlanRecords);
var costPlanSysIds = costPlanBatchOperations.process();