logo

NJP

Populate RITM Price Field with Catalog String Variable

Import · Mar 09, 2021 · article

While we're still currently on Orlando, I think this would apply to almost any supported version. Note that this simple solution would apply in environments following a similar Catalog Item pricing framework.

Not all Catalog Items have standard pricing models associated with them. For instance, we provide a workflow driven procurement request we call "PurchaseNow", where the Requester provides a total cost for items being requested in a string variable. However, the RITM's Price field and the Variable Formatter available in the Approver form have no default or OOB method to write that cost string into the Price field. To solve that problem, the best method turned out to be a fairly simple Business Rule on the Requested Item table (sc_req_item).

Note that the code below handles integers and decimals okay but does not address the issue of other non-number characters in the variable's string field. That would need to be handled with some more code depending on your environment.

Create the Business Rule with these attributes:

Table: sc_req_item

Run at: Server

Advanced : checked

When to run:
When: Before

Insert: checked

Update: checked

Filter Conditions: [Your Request Item] or other conditions befitting your environment

Actions:
We leave this blank, although you may find you need to configure something in this section

Advanced:
Conditions:None

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Copy string value from variable to RITM Price field
    current.price = current.variables.purchase_total_cost;

})(current, previous);

The other side benefit to this is that if the variable's string value changes in the active RITM or associated Workflow Tasks, the price field also updates in real time.

Please mark as Helpful if applicable. Thanks!

View original source

https://www.servicenow.com/community/developer-articles/populate-ritm-price-field-with-catalog-string-variable/ta-p/2299987