Hello,
The below script is designed to do the following;-
1. There are main quadrants in the Table, each quadrant has been assigned a whole number like 1, 2, 3 and so on. Each quadrant has sub quadrant like
1.1,1.2, 1.3 or 2.1, 2.2, 2.3 etc .... Only the sub quadrants have the ability to create instance using + and + buttons on the screen.
2. The script deals in generation of new numbers whenever the instance is created, the script caputures the present present number and in the loop subtracts
the quadrants 1 by 1, till the time number is < 1. From here on the loop will consider all the entries and add .1 till the time number generated by process
addition does not match, the present number. ex. continues addition will give you the numbers like 2.1, 2.2, 2.3 etc .... but if the actual number is loop does
not exist, for instance addition gives us 2.3 ...but in table if the numbers are till 2.2, and the next number is 3, it is here script will add a new number.
3. My problem is that script works fine till creating a second quadrant, the moment I create a third quadrant, the new number generated is 2.3000000000000003
and I cannot understand why? Kindly go through the script and suggest accordingly.
var nItemsLength = HAP_DOCUMENT.T_ELEMENTS.DATA.instanceManager.count; //oItems.nodes.length;
var n = " ";
var new_num = 0;
var gen_num = 0;
for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++) { // Begin Loop 1
var apLevel = "HAP_DOCUMENT.T_ELEMENTS.DATA["+ nItemCount +"].AP_LEVEL";
var row_Id = "HAP_DOCUMENT.T_ELEMENTS.DATA["+ nItemCount +"].ROW_IID";
var num_Id = "HAP_DOCUMENT.T_ELEMENTS.DATA["+ nItemCount +"].display.NUMBERING";
var nIndex = "HAP_DOCUMENT.T_ELEMENTS.DATA["+ nItemCount +"]";
var dName = xfa.resolveNode(apLevel).rawValue;
var eName = xfa.resolveNode(row_Id).rawValue;
var fName = xfa.resolveNode(num_Id).rawValue;
var eIndex = xfa.resolveNode(nIndex).index;
xfa.host.messageBox(" Present Index " + eIndex);
if (n == " ") { //Check for the Flag for Calulation
if ( dName == "2" ) { //( oItems.nodes.item(nItemCount).AP_LEVEL.value == "2" ) {// "3" ){ // Loop on Quadrants only
var x = fName; // Assign the Value of current Value from the loop
var y = sub_T_ELEMENTS.display.NUMBERING.rawValue; // Current Value from the Sub form
var z = parseFloat(y) - parseFloat(x); // Subtract the Values
if (z < 1) { //(z == 0) { // Check if the Value is greater than 1.
n = "X"; // Set the Flag and Stop calculation
// xfa.host.messageBox(" Flag Set ");
} // Check for Z
} // Check for Quadrants
} // Check for Flag
else { // Enter only when the flag is "X"
if ((new_num == null) || (new_num == " ")) { // ((old_num == null) || (old_num == " ")) {
new_num = fName;
// old_num = fName;
// xfa.host.messageBox("Assign Number " + fName);
}
else{
var add_num = .1;
gen_num = new_num;
new_num = 0;
gen_num = parseFloat(gen_num) + parseFloat(add_num);
new_num = gen_num;
if (new_num != fName){
store_form.NUMBERING.rawValue = new_num;
//nIndex = xfa.resolveNode(row_Id).rawValue;
nIndex = eName;
xfa.host.messageBox(" New Number " + new_num);
break;
}
}
}
}