needing to use toString in current.variables to convert value from a maintain item form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 10:39 AM
I have a Catalog form that takes in a string in the form of a dollar amount $5.00
I'm putting that into a table that has a cost field set as currency.
Doing a background script it works:
removed all the variables not related to this issue- the rest of them are populating
var operational_spend_per_month = "$5000.00",
var operationalSpend = operational_spend_per_month.substring(1,15);
var tableGr = new GlideRecord('x_table_name');
tableGr.addQuery('name', account_name);
tableGr.query();
// If the account name doesn't exist insert the values from the form:
if(!tableGr.hasNext()){
tableGr.initialize();
tableGr.setValue('name', account_name);
tabletGr.setValue('cost', operationalSpend);
tableGr.insert();
}
But when I use this in the worklfow using current.variables
var awsAccountGr = new GlideRecord('x_wec_sn_rel_mgt_aws_account_management');
var operationalSpend = current.variables.operational_spend_per_month.substring(1,15);
var tableGr = new GlideRecord('x_table_name');
tableGr.addQuery('name', account_name);
tableGr.query();
// If the account name doesn't exist insert the values from the form:
if(!tableGr.hasNext()) {
tableGr.initialize();
tableGr.setValue('name', current.variables.account_name.account_name);
tabletGr.setValue('cost', operationalSpend);
tableGr.insert();
}
I've logged current.variables.account_name.account_name and operationalSpend, the results are like $55.00 and undefined, respectively. When I log in the background script I get $55.00 and 55.00, respectively.
I saw another post needing to use toString(). which I tried:
var operationalSpend = current.variables.operational_spend_per_month.toString().substring(1,15);
which resulted in NaN,
should I try parseFloat() ? seeing as it technically is a float?
var operationalSpend = parseFloat(current.variables.operational_spend_per_month.substring(1,15));
Thanks,
Robb
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 11:25 AM
Hi Robb,
Check this link please.
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 01:28 PM
Here is what I came up with that fixed the issue:
var tempValue = current.variables.operational_spend_per_month;
var costString = tempValue.toString().replace(/\$/g,'');
var operationalSpend = parseInt(costString);
it was based off this solution to a similar problem: