-1

This looks like it should work but for some reason the indexed value is not being removed. I think it must be something really simple but??? Here is the code:

var debug:Boolean = true;
    var rtn:Array = database.getView("vwWFSApplicationsEnabled").getColumnValues(0);
    var i:Integer = rtn.indexOf("Admin");
    if (debug) print ("Position of Admin = " + i + " rtn = " + rtn.toString() )
        
    if (i >= 0){
        if (debug) print("In splice  " )
        rtn.splice(i , 1);
        if (debug) print("after Splice  " + rtn.toString() )
    }       
    return rtn.unshift("--- Select Application ---");

When it runs I get this in the log:

HTTP JVM: Position of Admin = 1 rtn = [Absence Requests, Admin, Demo]

HTTP JVM: In splice

HTTP JVM: after Splice [Absence Requests, Admin, Demo]

i is being set in the indexOf to 1 which is correct so the splice(i, 1) should remove the value Admin from the array but after the splice the value Admin is still in the list. I've used the split in other situations and it works there but I can't see any difference in this code.

Community
  • 1
  • 1
Bill F
  • 2,057
  • 3
  • 18
  • 39

2 Answers2

1

It's clear from the example you have your own custom Array type. I say this because:

  • Array#toString doesn't produce output like that (it doesn't put [] around its outputs, and it would put quotes around string values)
  • Array is not a legal declaration in TypeScript
  • Your code doesn't work

Whatever custom Array type you are using simply doesn't implement splice correctly and we can't diagnose that problem without the relevant code.

Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235
0

NotesView.getColumnValues(n) returns a Vector (java.util.Vector) and not a SSJS Array (com.ibm.jscript.std.ArrayObject). Hence you have to use Vector.remove(i) to get rid of the given element. Also, Vector does not support unshift - you would have to replace it with Vector.add(0,x).

In case you decide to go with a different approach, namely to convert the Vector to a SSJS Array and keep the rest of your code untouched I want to state the following: Array.splice() definitely works in SSJS (at least since Domino 8.5.3). If older versions do not support it you can easily write a prototype for Array.splice. Additionally, keep in mind that in the current SSJS implementation, Array.splice works slightly different than in client-side JavaScript (CSJS): In CSJS it returns the removed elements, while in SSJS it returns the newly created array.

xpages-noob
  • 1,569
  • 1
  • 10
  • 37