Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using flow activity or function to add Cost Fields.

EricG
Kilo Sage

I'm stuck on a flow i've created.

 

The basic function is to allow users to select multiple Hardware Assets at one time.

I can update the Asset and associated CI with no issues.

 

Now, I need to add all costs associated to each Asset and put that in the Flow Variable, so that i can update the Catalog variable for reporting.

 

I have a client script for a similar form that can do this.

	var newPrice = unit.replace('$', '');
	var existPrice = g_form.getValue("device_total_cost").replace('$', '');
	
	var extendPrice = "";
	extendPrice = Number(existPrice) + Number(newPrice);
	//alert("Not sure why values are not adding. Unit = "+unit+", New Price = "+newPrice+", Exisitng Price = "+existPrice+" for total of "+extendPrice);
	g_form.setValue('device_total_cost',"$"+parsefloat(extendPrice).toFixed(2));

 

I'm trying to avoid creating a custom Flow Action and thought to use the functions available to the Pill Record.

It's not working.

Code is 

var origCst = fd_data._8__look_up_hardware_record.cost;//.replace("$","");
var origFVCst = fd_data.flow_var.cpu_ttl_cost;//.replace("$","");
var newTTL = origCst+origFVCst;

return "$"+parseFloat(newTTL).toFixed(2);

but i'm getting this error

EricG_0-1737134653132.png

 

If i just put the pill records together in the Flow Logic activity

EricG_1-1737134738332.png

I get this.  

 

EricG_4-1737135198179.png

while this is acceptable for Serial numbers, the costs don't make sense.

 

Any suggestions on a solution.

 

 

1 ACCEPTED SOLUTION

Can you try parseInt or parseFloat with mentioning base 10? It can be done. Like below if that works.

var a = '123';

var b = parseInt(a, 10);

 

View solution in original post

8 REPLIES 8

Animesh Das2
Mega Sage
Mega Sage

Hi @EricG ,

 

The error looks like the 'cost' is not reference from the step 'look up record' action is step number 8 of your flow.

Can you modify the line as below if that error gets fixed.

 

var origCst = fd_data._8__look_up_hardware_record.record.cost;

 

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

EricG
Kilo Sage

@Animesh Das2 well I've looked at Steps 6, 7 and 8.

 

In #6 i'm parsing out a List Collector to get the SYS_ID's of the alm_hardware selected.

Then in Step 7, doing a For loop for each value from #6

Step 8 looks up the alm_hardware record from #7, which the table has cost as a table column.

 

Here is the original flow with just using the Pill + Pill.  As you can see, I am getting the Cost Value of that record.

EricG_0-1737144300263.pngEricG_1-1737144377024.png

So, the variable on the RITM shows "+0+952.03+0"

First value had no cost (0), Secon had 952.03, while last had 0.

 

Should i be putting this as a String or Variable?

I'm not getting why the Pill + Pill will return a value, while the Script isn't.

@EricG , can you share the screenshots of the steps where you are facing the issue with script approach, and along with pill + pill stuff which is working?

However, for concatenation you always need to convert a variable into string before. Like you can convert the line that I shared in my previous reply into string as,

 

var origCst = fd_data._8__look_up_hardware_record.record.cost.toString();

 

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

OK, let me restate, that the Cost Flow Variables are not returning the desired results.

I do not need these to be concatenated, but summed.

Here is a shot of where I'm updating the Selected alm_hardware from the cat_item

EricG2_0-1737465361777.png

I am getting the sys_id of the asset, so then I look that record up

so after updating the asset to "Deployed", I'm setting my flow variables

EricG2_1-1737465458264.png

My thinking it is to set Cost and Total Cost with the assets model cost for Loop pass 1

Then, with loop pass 2+, replace cost with asset2 cost and update TTL with existing + new value of asset 2+.

The screen shot above gives me the concatenated costs $1+$2+etc..., which is not wanted.

var origCst = fd_data._8__look_up_hardware_record.cost;//.replace("$","");
var origFVCst = fd_data.flow_var.cpu_ttl_cost;//.replace("$","");
var newTTL = origCst+origFVCst;

return "$"+parseFloat(newTTL).toFixed(2);

This script is what is giving me the ref error.