{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":32770,"path":"it-service-management/expense-line/t_UseAScriptedAllocation.md","title":"Use a scripted allocation","bundle":null,"doc_type":null,"release":"australia","body":"\n# Use a scripted allocation\n\nScripted allocations define custom allocation amounts and targets by executing a script.\n\n## Before you begin\n\nRole required: admin, financial\\_mgmt\\_admin, or financial\\_mgmt\\_user\n\n## About this task\n\nYou can use scripted allocations to perform any of the following actions.\n\n-   Allocate an expense to all cost centers based on the current head count in the cost center.\n-   Query usage data to determine the allocation amount to assign to a target.\n-   Track the business users that are consuming business services.\n\n## Procedure\n\n1.  Navigate to **All** &gt; **Costs** &gt; **Administration** &gt; **Expense Allocation Rules**.\n\n2.  Select an expense allocation rule.\n\n3.  Select the **Advanced** check box.\n\n4.  Use the following concepts to build the script\n\n    -   Query for target records and data to use for calculating the allocation amount.\n    -   Create allocation records using the ExpenseAllocation API.\n    The following variables are available during the script processing:\n\n    -   **allocation**: expense allocation object used to create allocations.\n    -   **expense**: GlideRecord for the expense\\_line that is being processed.\n    -   **rule**: GlideRecord for this rule.\n    To create an allocation record, use the allocation object already instantiated in the script scope:\n\n    ```\n    allocation.createAllocation(targetGlideRecord, amount);\n    ```\n\n\n**Parent Topic:**[Expense lines and expense allocations](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-service-management/expense-line/c_ExpenseLinesAndAllocations.md)\n\n**Related topics**  \n\n\n[Create an allocation rule]()\n\n[Automatic expense line creation]()\n\n[Create expense lines manually]()\n\n[Delete an expense line]()\n\n[Create a sample allocation rule]()\n\n"}}