CostPlanBatchOperations - Global
- UpdatedAug 1, 2024
- 3 minutes to read
- Xanadu
- API reference
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.
| Name | Type | Description |
|---|---|---|
| costPlan | Object | One or more objects or an array of objects that describe each of the cost plans to add to an existing task. |
| costPlan.name | String | Name of the cost plan. Maximum length: 130 characters |
| costPlan.task | String | Sys_id of the project or demand to associate with this cost plan. You can
locate this value in one of the following tables:
|
| costPlan.unit_cost | Number | Cost of a single unit of the specified resource. |
| costPlan.resource_type | String | Sys_id of the record that defines the cost type associated with this cost plan. The available values for this parameter are defined in the Cost Type Definition [resource_type_definition] table. |
| costPlan.start_fiscal_period | String | Sys_id of the record that defines the starting fiscal period to associate with this cost plan. The available values for this parameter are defined in the Fiscal period [fiscal_period] table. |
| costPlan.end_fiscal_period | String | Sys_id of the record that defines the ending fiscal period to associate with this cost plan. The available values for this parameter are defined in the Fiscal period [fiscal_period] table. |
| costPlan.<optional> | Varied | Optional. You can pass in additional parameters to add to a cost plan. The
available parameters depend on the type of cost plan that you are creating. Refer to the Cost Plan [cost_plan] table for the list of additional parameters that you can pass. |
| 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.
| Name | Type | Description |
|---|---|---|
| None |
| 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.
| Name | Type | Description |
|---|---|---|
| None |
| 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();