In Incident Table there is field add two numbers should populate in 3rd field , but the problem is the number should be in eg : 0001 + 0002 = 0003 000

Pravin Yadav1
Tera Contributor

In Incident Table there is field add two numbers should populate in 3rd field , but the problem is the number should be in eg : 0001 + 0002 = 0003

Answer should be in this format  0003

 

please help me

I have written this code in Business rules :

 var x = current.u_integer_7;
    var y = current.u_integer_5;
    gs.addInfoMessage(x);
    var z = x + y;
    current.u_integer_6 = z;

1 ACCEPTED SOLUTION

Hello @Pravin Yadav 

This is not possible with Integer type of field that is not possible. If you want to acheive this requirement then you have to use the String type field and in Client script you can validate that if the value entered in num1 and num2 are not numer then display error Message. Something like below:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (isNaN(newValue)) {
        g_form.clearValue("u_num1");
        g_form.showFieldMsg("u_num1", "Enter Numeric value", "error");
    } else {
        var lengthNum1 = g_form.getValue("num1").length;
        var lengthNum2 = g_form.getValue("num2").length;
        var length = lengthNum2;
        if (lengthNum1 > lengthNum2) {
            length = lengthNum1;
        }
        var totalValue = parseInt(g_form.getValue("num1")) + parseInt(g_form.getValue("num2"));
        var finalValue = pad(totalValue.toString(), length);
        alert(finalValue);
        g_form.setValue("add", finalValue);
    }

    function pad(num, size) {
        num = num.toString();
        while (num.length < size)
            num = "0" + num;
        return num;
    }
}

Similarly 1 client script on Num2 field.

Else you can use similar logic in your BR

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. This will help others with similar issue to find the correct answer.

Thanks

View solution in original post

4 REPLIES 4

Uncle Rob
Kilo Patron

You're thinking in terms of integers (which never format with leading zeros).  You need to think in terms of string, at least for output.

This stackOverflow page looks to have a lot of options for you. 

function pad(num, size) {
    num = num.toString();
    while (num.length < size) num = "0" + num;
    return num;
}

Thanks for response

@Robert Fedoruk

In the given field m getting the output, considering the output need to convert to string

and by getting the logic the value should be started from   0018.

 

 

find_real_file.png

Instead of 18.0  i need to get 0018

 

Thanks & regards

pravin

Hello @Pravin Yadav 

This is not possible with Integer type of field that is not possible. If you want to acheive this requirement then you have to use the String type field and in Client script you can validate that if the value entered in num1 and num2 are not numer then display error Message. Something like below:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (isNaN(newValue)) {
        g_form.clearValue("u_num1");
        g_form.showFieldMsg("u_num1", "Enter Numeric value", "error");
    } else {
        var lengthNum1 = g_form.getValue("num1").length;
        var lengthNum2 = g_form.getValue("num2").length;
        var length = lengthNum2;
        if (lengthNum1 > lengthNum2) {
            length = lengthNum1;
        }
        var totalValue = parseInt(g_form.getValue("num1")) + parseInt(g_form.getValue("num2"));
        var finalValue = pad(totalValue.toString(), length);
        alert(finalValue);
        g_form.setValue("add", finalValue);
    }

    function pad(num, size) {
        num = num.toString();
        while (num.length < size)
            num = "0" + num;
        return num;
    }
}

Similarly 1 client script on Num2 field.

Else you can use similar logic in your BR

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. This will help others with similar issue to find the correct answer.

Thanks

Thank you so much

@Mahendra.