Please use docs.servicenow.com for the latest documentation.

This site is for reference purposes only and may not be accurate for the latest ServiceNow version

ExpenseLine API

From Wiki Archive
Jump to: navigation, search


Overview

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.

Methods

Method Summary
Return Value Details
ExpenseLine initialize(GlideRecord source, Decimal amount, String description, GlideRecord costSource)
Instantiates new ExpenseLine object
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.
setDescription(String description)
Defines the a description of the expense
setRecurring(boolean recurring)
Flags the expense as recurring by setting the recurring field to true
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
setSummaryType(String summaryType)
Sets a value for the expense line summary_type field
boolean createExpense()
Creates the expense line record based on the parameters provided
processCIParents()
Used internally by the createExpense method to process CI relationships when the expense source is a cmdb_ci type record.

initialize

initialize(GlideRecord source, Decimal amount, String description, GlideRecord costSource)

Instantiates a new ExpenseLine object with basic required expense line data.
Parameters:
GlideRecord source - Required GlideRecord identifying the source of the expense
Decimal amount - Required Decimal identifying the amount of the expense
String description - Optional description of the expense
GlideRecord costSource - Optional GlideRecord identifying the source record that generated the expense line. This is generally only used for system generated expense lines (CI rate card, distribution costs, and task rate card processing)
Returns:
ExpenseLine object

setCostSource

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.
Parameters:
costSource - GlideRecord of CI rate card cost, distribution cost, or task rate card. This is generally only used for system generated expense lines.

setDescription

setDescription(String description)

Defines the a description of the expense.
Parameters:
description - Description of expense.

setRecurring

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).
Parameters:
recurring - true to identify expense line as a recurring expense

setParent

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.
Parameters:
expense - parent expense line record

setSummaryType

setSummaryType(String summaryType)

Sets a value for the expense line summary_type field.
Parameters:
summaryType - Typically you would set it to a value already specified in the expense line summary type field choice list

createExpense

createExpense()

Creates the expense line record based on the parameters provided.
Returns:
boolean true if the expense line was successfully created

processCIParents

processCIParents()

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

Example

<syntaxhighlight lang="JavaScript"> //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"); exp.setSummaryType("run_business"); var success = exp.createExpense(); gs.print("Successful? " + success); </syntaxhighlight>