I have question pertaining to calculating tax formula in ITSM/CMDB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 03:20 AM
Hi Everyone,
I have one requirement:
I have 3 fields: 1) Cost , 2) Tax and 3) Total Cost
1. Whenever I enter a number in the cost field, it should automatically update in the Tax field after multiplying by 0.50.
The formula is (Cost x0.50) = Tax.
2. The Total Cost field should be updated with the addition of cost and tax values.
formula would be (Cost + Tax) = Total Cost
It should be noted that the formula must function while altering the cost value at the form level.
Kindly suggest or help me what are the ways to achieve this requirement and please share related scripts
Regards,
Vishnu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 05:01 AM
Hi All,
I am grateful for your prompt responses.
I tried all scripts but it's not working, I'm getting the NaN values, please find the attached screenshot.
Regards,
Naveen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 05:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 05:25 AM
@Vishnu533
did you try onChange Client script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 07:29 AM
Hello @Vishnu533
From the screenshot I can see that the cost field is of type price/currency. This implies that data stored in cost field is stored as a string and therefore direct calculation is not possible.
To calculate the tax and total cost firstly we need to convert the string to integer and then perform the operation.
Here is the updated client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//set the tax and total cost value
var price = parseFloat(newValue.replace('£', ''));//please change the symbol to respective currency symbol
g_form.setValue('tax', price*0.5);
g_form.setValue('total_cost', price*1.5);
}
Additional you can use the following script the get the display value of cost field.
g_form.getDisplayValue('price');
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 08:40 AM
Hello @Juhi Poddar
Thank you for sharing updated script, the NaN value is not coming now but formula is not working, nothing showing in tax and total cost field.