- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 04:27 AM
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;
Solved! Go to Solution.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 07:12 AM
Hello
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 04:43 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 05:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 07:12 AM
Hello
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 10:20 PM
Thank you so much
@Mahendra.