0

need some help .. Recently I've just created an array to calculate the value

function Calculate(){   
for(x=1;x<7;++x){
    var targetArr = [];
    for(i=0;i<3;i++){
        targetArr[i] = getComponent("product_"+x).getValue();
        targetArr[i] = getComponent("quantity_"+x).getValue();
        targetArr[i] = getComponent("stock_"+x).getValue();
    }

    var actualArr = [];
    for(i=0;i<3;i++){
        actualArr[i] = getComponent("actualProduct_"+x).getValue();
        actualArr[i] = getComponent("actualQuantity_"+x).getValue();
        actualArr[i] = getComponent("actualStock_"+x).getValue();
    }

    var achArr = [];
    for(i=0;i<3;++i){
        if((actualArr[i]>targetArr[i])||(targetArr[i]==0)||(targetArr[i]=="")||(targetArr[i]==null)){
            achArr[i] = 1;
        }else{
            achArr[i] = (actualArr[i] / targetArr[i]);
        }
        if(isNaN(achArr[i])){
            achArr[i] = 0;
        }
        x0 = achArr[i][x];
        x1 = achArr[i][x];
        x2 = achArr[i][x];
    }
    value = 100;

    currentDocument.replaceItemValue("achProduct_"+x, x0*Value);
    currentDocument.replaceItemValue("achQuantity_"+x, x1*Value);
    currentDocument.replaceItemValue("achStock_"+x, x2*Value);
}}

but when i run the script, its got forever looping on my lotus domino server and when i try to restart the web server its stucked and i have to force closed the server, and manually open it again

anyone can help me to solve my case ? i just need to display the achArr values

  • This might help: http://stackoverflow.com/questions/966225/how-can-i-create-a-two-dimensional-array-in-javascript – kol Mar 27 '14 at 10:04

1 Answers1

0

I'm trying to decipher your goal here. But first of all, your targetArr and actualArr for loops are wrong.

You'll end up with all values in targetArr equal to getComponent("stock_"+x).getValue()

Similarly, all values in actualArr equal to getComponent("actualStock_"+x).getValue()

And I don't think you even need a 2D array for achArr. I'm not entirely sure what you want to calculate in achArr's values, but I've written the code below. Is this closer to what you want?

function Calculate(){   
for(var x=1;x<7;x++){
    //Retrieve targetArr values
    var targetArr = [];
    targetArr[0] = getComponent("product_"+x).getValue();
    targetArr[1] = getComponent("quantity_"+x).getValue();
    targetArr[2] = getComponent("stock_"+x).getValue();

    //Retrieve actualArr values
    var actualArr = [];
    actualArr[0] = getComponent("actualProduct_"+x).getValue();
    actualArr[1] = getComponent("actualQuantity_"+x).getValue();
    actualArr[2] = getComponent("actualStock_"+x).getValue();

    //Generate achArr values
    var achArr = [];
    for(var i=0;i<3;i++){
        if((actualArr[i]>targetArr[i])||(targetArr[i]==0)||(targetArr[i]=="")||(targetArr[i]==null)){
            achArr[i] = 1;
        }else{
            achArr[i] = (actualArr[i] / targetArr[i]);
        }
        if(isNaN(achArr[i])){
            achArr[i] = 0;
        }
    }
    var value = 100;

    currentDocument.replaceItemValue("achProduct_"+x, achArr[0]*value);
    currentDocument.replaceItemValue("achQuantity_"+x, achArr[1]*value);
    currentDocument.replaceItemValue("achStock_"+x, achArr[2]*value);
}}
Brian Gleeson - IBM
  • 2,565
  • 15
  • 21