- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 11:12 AM
Hi All,
I am new to this community and ServiceNow and have zero scripting experience. So, is there any way to aggregate two integer fields without scripting?
Simpley, The calculation should be: Total Units= Total Units + Add Tokens.
Regards,
Mo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 11:50 AM
Hi @Mohamed Elsayed ,
There is a way without using GlideAggregate you can simplly do like -
Right click on the field in which you need to store the response and add this line of code
(function calculatedFieldValue(current) {
// Add your code here
var a = current.u_a;
var b = current.u_b;
var c = current.u_c;
var d = current.u_d;
return a+b+c+d; // return the calculated value
})(current);
For emaple in my Incident form there a 5 fields - A,B,C,D and E
E stors the sum of A,B,C,D
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 11:50 AM
Hi @Mohamed Elsayed ,
There is a way without using GlideAggregate you can simplly do like -
Right click on the field in which you need to store the response and add this line of code
(function calculatedFieldValue(current) {
// Add your code here
var a = current.u_a;
var b = current.u_b;
var c = current.u_c;
var d = current.u_d;
return a+b+c+d; // return the calculated value
})(current);
For emaple in my Incident form there a 5 fields - A,B,C,D and E
E stors the sum of A,B,C,D
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2024 03:21 AM
Thanks Sartha,
I used it and it works but the result is always triple what it should be. So, for example, when I add 100 to the field (Add Tokens) which is (B) in the script. The script adds 300 to the (Total Units) which is (A) in the script.
The script:
(function calculatedFieldValue(current) {
// Add your code here
var a = current.total_units
var b = current.u_add_tokens
return a+b; // return the calculated value
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 10:15 PM
@Mohamed Elsayed If you wish to configure the average on a list within in ServiceNow then you can use List calculations. https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/list-adminis...
However, if you wish to do it at form level then you will have to use Calculated field https://www.servicenow.com/community/developer-blog/calculate-value-field-use-case/ba-p/2386808 or a function field https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/build/platform-function... and little bit of scripting to calculate the average.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2024 03:31 AM
Hi @Mohamed Elsayed ,
You can also use Formula Builder - Formula Builder || Use of Formula Builder || New Concept ServiceNow (youtube.com)