How to use a negative value in table's variable (integer type variable)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2022 01:54 AM
I want the value of the variable field integer in the negative, there is some script is running background to calculate the client priority in an incident I need to make the variable value negative so that it will work as excepted. this is an Integer type variable.
Thank you,
Mano
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2022 01:59 AM
Hi,
So is it not allowing negative values by default in an integer field?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2022 02:56 AM
yes it's not allow negative values by default it's allowing us to save the form with negative value but the calculation is not happening with that negative value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2022 03:59 AM
Hi,
So negative value is getting saved in that field but during calculation it's not happening
share your script
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2022 04:21 AM
getClientPriority - calculates the client index result and client priority
** Where used: client script on Outage table, BR on outageOtable.
** Parameters: scale (integer) for Impact Category, User Base, Client Classification, Time Classification, Workaround
** Returns: JSON of values
*/
getClientPriority: function(impactCat, userBase, clientClass, timeClass, workaround) {
var impactCatScale = this.getClientIndexScale(impactCat);
var userBaseScale = this.getClientIndexScale(userBase);
var clientClassScale = this.getClientIndexScale(clientClass);
var timeClassScale = this.getClientIndexScale(timeClass);
var workaroundScale = this.getClientIndexScale(workaround);
var clientPriorityDivisor = gs.getProperty('sn_major_inc_mgmt.client_priority_divisor');
// STRY0032767 Properties used to control client priority ranges
var cp4top = gs.getProperty('cp.4.top');
var cp3bottom = gs.getProperty('cp.3.bottom');
var cp3top = gs.getProperty('cp.3.top');
var cp2bottom = gs.getProperty('cp.2.bottom');
var cp2top = gs.getProperty('cp.2.top');
var cp1bottom = gs.getProperty('cp.1.bottom');
var clientIndexResult = '';
// if all the elements of the calculation have a value of zero or more, then complete the calculation
if (clientPriorityDivisor >= 0 && impactCatScale >= 0 && userBaseScale >= 0 && clientClassScale >= 0 && timeClassScale >= 0 && workaroundScale >= 0) {
clientIndexResult = (impactCatScale + userBaseScale + clientClassScale + timeClassScale + workaroundScale) / clientPriorityDivisor;
}
var clientPriority;
// get the priority based on the client index result value
// Updated to use properties to control the ranges for which priorities should apply
if (clientIndexResult == '') {
clientPriority = '';
} else if (clientIndexResult >= 0 && clientIndexResult < cp4top) {
clientPriority = 4;
} else if (clientIndexResult >= cp3bottom && clientIndexResult < cp3top) {
clientPriority = 3;
} else if (clientIndexResult >= cp2bottom && clientIndexResult < cp2top) {
clientPriority = 2;
} else if (clientIndexResult >= cp1bottom && clientIndexResult <= 1.0) {
clientPriority = 1;
}
var results = {
"clientIndexResult": clientIndexResult,
"clientPriority": clientPriority
};
return JSON.stringify(results);
},