jonsan09
Tera Sage

In my "How to Bulk Populate Asset Costs in HAM Using Flow Designer Flows & Subflows" article, I detailed how to bulk update asset costs using a subflow paired with a scheduled flow. 

 

The scheduled flow handles your routine weekly run just fine. But sometimes you don't want to wait for the next scheduled run. Instead of running the whole scheduled flow, you can add a link right on the Hardware Model record to trigger the subflow for just that model.

Before You Start

This builds directly on the subflow from the first article. If you haven't set that up yet, go do that first and come back here.

 

One thing to double-check: This UI Action uses two outputs back from the subflow:  a count (Integer) and a message (String). If you didn't add outputs when you built the subflow your banner message will come back blank. The count is just the number of asset records updated.

 

Building the UI Action

 

1. Create it on the right table

Navigate to System Definition > UI Actions (or right-click the Hardware Model form header and configure). Set the Table to cmdb_hardware_product_model.

 

2. Name and placement

Give it a name, I used: Populate Empty Asset Costs. Check Form link to have it appear under Related Links at the bottom of the record. Set Order to 100 (personal preference for position on form).

 

chrome_ghl3T2NRGw.png

 

3. Lock it down with a Condition

Use the Condition field to gate visibility by role. I limited mine to admins and category managers:

gs.hasRole("admin") || gs.hasRole("category_manager")

Add or change to whatever roles fit your team.

 

4. The Script

Open your subflow in Flow Designer and grab the auto-generated code snippet from the subflow's menu.

chrome_OARXiSDrfv.png

 

Paste it into the UI Action script and adjust:

var inputs = {};
inputs['override_existing_asset_costs'] = false; // True/False
inputs['hardware_model'] = current; // GlideRecord of table: cmdb_hardware_product_model

// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().subflow('your_scope.your_subflow_name').inBackground().withInputs(inputs).run();

// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('your_scope.your_subflow_name').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();

// Get Outputs:
// Note: outputs can only be retrieved when executing synchronously.
var count = outputs['count']; // Integer
var message = outputs['message']; // String

gs.addInfoMessage('Number of Assets updated: ' + count);

 

Note: Replace your_scope.your_subflow_name with your actual subflow scope and sys_name. The exact string is in the auto-generated snippet from Flow Designer.

 

 

What the Script Is Actually Doing

current is the model you're on. Because this UI Action lives on the Hardware Model form, current is the exact record you clicked from. That gets passed into the subflow's hardware_model input.

 

Override is set to false.  We're only filling in the blanks ($0 / empty costs). Not overwriting existing values. If you need a force-update version, build a second UI Action for it and keep the default safe.

 

Synchronous vs. asynchronous. I'm running it synchronously (inForeground()) on purpose — that's the only way to read the outputs back and tell the user what happened. The commented-out asynchronous (inBackground()) option is better for very large updates, but you lose access to the outputs. Choose based on how many assets your models typically have.

 

The confirmation message. Once the subflow finishes, we grab the count output and surface it with gs.addInfoMessage() — the user gets a clean "Number of Assets updated: X" banner instead of wondering if anything happened.

 

Trying It Out

Open any Hardware Model record that has a cost populated and at least one hardware asset sitting at $0.00. Scroll to Related Links, click Populate Empty Asset Costs, and you should see the info message confirming how many records were updated.

 

chrome_LA6GYtHIOI.png

 

 

As always, build and test in your Subprod instances before activating it in Production. 

Version history
Last update:
2 hours ago
Updated by:
Contributors