How to use a negative value in table's variable (integer type variable)

Mano R
Tera Contributor

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.

find_real_file.png

Thank you,

Mano

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So is it not allowing negative values by default in an integer field?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

Hi,

So negative value is getting saved in that field but during calculation it's not happening

share your script

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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);
    },