ExpenseLine - Global

The ExpenseLine API is included with the Cost Management Plugin as a script include record. It is used by various cost management processes and can also be used for generating expense line (fm_expense_line) records from your own server-side scripts.

ExpenseLine - createExpense()

Creates a new expense line record.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
Boolean True if the expense line was successfully created.

//get some random CI to be used as an expense sourcevar ci =new GlideRecord("cmdb_ci_server");
ci.query();
ci.next();
 
//create expense line
var exp =new ExpenseLine(ci,234.56,"Test expense line");
exp.setSummaryType("run_business");
var success = exp.createExpense();

ExpenseLine - ExpenseLine (GlideRecord source, Number amount, String description)

Constructor for ExpenseLine object.

Table 3. Parameters
Name Type Description
source GlideRecord GlideRecord identifying the source of the expense
amount Number Decimal number identifying the amount of the expense
description String (Optional) Description of the expense.
Table 4. Returns
Type Description
ExpenseLine object The ExpenseLine object just instantiated.

//get some random CI to be used as an expense source
        var ci = new GlideRecord("cmdb_ci_server");
        ci.query();
        ci.next();
        
        //create expense line
        var exp = new ExpenseLine(ci, 234.56, "Test expense line");

ExpenseLine - processCIParents()

Used internally by the createExpense method to process CI relationships when the expense source is a cmdb_ci record.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
void


      
      

Output:

ExpenseLine - setCostSource(GlideRecord costSource)

Identifies the source rate card or distribution cost that was the source of expense line generation.

This is not the source (CI, task) of the expense.

Table 7. Parameters
Name Type Description
costSource GlideRecord GlideRecord of CI rate card cost, distribution cost, or task rate card. This is generally only used for system-generated expense lines.
Table 8. Returns
Type Description
void


      
      

Output:

ExpenseLine - setDescription(String description)

Defines the description of an expense.

Table 9. Parameters
Name Type Description
description String Description of expense.
Table 10. Returns
Type Description
void


      
      

Output:

ExpenseLine - setParent(GlideRecord expense)

Sets the parent field on the expense line.

This is generally only used by the system when generating indirect expenses such as business service aggregated expenses.

Table 11. Parameters
Name Type Description
expense GlideRecord Parent expense line record.
Table 12. Returns
Type Description
void


      
    

ExpenseLine - setRecurring(Boolean recurring)

Flags the expense as recurring by setting the recurring field to true.

Expense lines are set to false by default so there is no need to call setRecurring(false).

Table 13. Parameters
Name Type Description
recurring Boolean Set to true to identify expense line as a recurring expense.
Table 14. Returns
Type Description
void


      
    

ExpenseLine - setSummaryType(String summaryType)

Sets a value for the expense line summary_type field.

Table 15. Parameters
Name Type Description
summaryType String Typically you would set this to a value already specified in the expense line summary type field choice list.
Table 16. Returns
Type Description
void

//get some random CI to be used as an expense sourcevar ci =new GlideRecord("cmdb_ci_server");
ci.query();
ci.next();
 
//create expense line
var exp =new ExpenseLine(ci,234.56,"Test expense line");
exp.setSummaryType("run_business");

Output: