0

I would like to change the value of a field in the backend document of the clicked row in a view, but also of the previous row. What could be the best way of dooing this ?

Lothar Mueller
  • 2,528
  • 1
  • 16
  • 29
Marc Jonkers
  • 496
  • 1
  • 7
  • 17

1 Answers1

1

Interesting topic. I just gave it a try and found this solution:

I assume you're using a view panel (using something like a repeat instead might make things a bit easier, though). Under "All properties" of your viewPanel look for the property called "data > var" (take care: there's also a "data > data > var", but that's a different thing!). Here you enter a unique name to access your view entries:

<xp:viewPanel rows="30" id="viewPanel1" var="entry">        
    <xp:this.data>
        <xp:dominoView var="view1" viewName="myView"></xp:dominoView>
    </xp:this.data>

I added an extra column making its data property computed, calculating the previous entry using the current entry's parent view Navigator object, and making sure that both the current and the previous entries are valid View Entry objects. Then, as a result I return the previous entry's NoteID value to make sure that I indeed accessed it.

if(!entry.isCategory()){
    var vnav:NotesViewNavigator = entry.getParent();
    vnav.gotoEntry(entry.getDocument())
    var pentry = vnav.getPrev();
    if(pentry!=null){
        pentry.getNoteID();
    }
}

To be able to check this properly I added one more column to show the current entry's NoteID:

entry.getNoteID();

The result looks like this:

enter image description here

So, once you have the previous object you also have access to its document object.

Edit: how to get the viewNavigator object the ordinary way:

simply create your viewNavigator using the parent view object as in

var view = database.getView("myView);
var vnav = view.createViewNav();

On the other hand if you see that entry.getParent() leads to a viewEntryCollection you might as well try to access the prvious entry in a different way:

var vec = entry.getParent();
if (vec.toString().indexOf("ViewEntryCollection")>0){
    var preventry = vec.getPrevEntry(entry);
}
Lothar Mueller
  • 2,528
  • 1
  • 16
  • 29
  • I'm getting an error on line 3 : vnav.gotoEntry(entry.getDocument()) Script interpreter error, line=3, col=10: [TypeError] Error calling method 'gotoEntry(lotus.domino.local.Document)' on an object of type 'lotus.domino.local.ViewEntryCollection [Static Java Interface Wrapper, lotus.domino.local.ViewEntryCollection: lotus.domino.ViewEntryCollection]' – Marc Jonkers Jul 19 '12 at 11:33
  • this is interesting: that means that the parent object to your "entry" is a viewEntryCollection, while it is a ViewNavigator on my side. You can verify this by commenting out the entire code. Then you write a new code line just for debugging purposes: entry.getParent().toString(); – Lothar Mueller Jul 19 '12 at 11:54
  • Anyway, if you receive a viewEntryCollection then you'll have to create the viewNvaigator the standard way like NotesView.createViewNav(); Then you should be able to follow the original code... Maybe later on I'll post an alternative method using a repeat control if I find the time – Lothar Mueller Jul 19 '12 at 12:05
  • entry.getParent().toString(); Gives in this column : lotus.domino.local.ViewEntryCollection@26322632 for each row it is the same. Is that normal ? The entry.getNoteID(); Gives correctly for example 11FE , 123A and so on – Marc Jonkers Jul 20 '12 at 07:04
  • It seems I'm having this problem mentioned above (error on line 3) because I have a search on this view. When I remove the search it works. – Marc Jonkers Jul 20 '12 at 07:51
  • You say to create the viewNavigator. Could you help me with that. I don't get it to work – Marc Jonkers Jul 20 '12 at 07:57
  • I'll edit my original answer, easier than using this comment simplicistic editor – Lothar Mueller Jul 20 '12 at 08:04
  • re: your comment about the entry.getParent().toString() result: yes, this of course is normal as you're always asking the same thing... – Lothar Mueller Jul 20 '12 at 08:21
  • Thanks for the update, but actually it still doesn't work. When I create the viewNavigator as indicated above, it works when I don't add my search in my view. Once I add the search I'm getting the script interpreter error again. – Marc Jonkers Jul 20 '12 at 09:25
  • The code for my search is : var tmpArray = new Array(""); var cTerms = 0; if (sessionScope.country != null & sessionScope.country != "") { tmpArray[cTerms++] = "(FIELD bbland = \"" + sessionScope.country + "\")"; } if (sessionScope.product != null & sessionScope.product != "") { tmpArray[cTerms++] = "(FIELD bbproduct = \"" + sessionScope.product + "\")"; } qstring = tmpArray.join(" AND ").trim(); return qstring – Marc Jonkers Jul 20 '12 at 09:25
  • sorry, my mistake, didn't read your note about "view search" properly. In that case things are more complicated, I'm afraid. You'll have to do some testing whether you can access next or prvious entries from a ve-collection if the view is filtered. Also the viewNavigator object will be different from what you get using the method I recommended - sorry, I would have to test this my self. But all in all, those objects you're trxying to use here are the same as the ones you use in any LotusScript coding. Maybe you can try there, and at least you have some runtime debugger helping you – Lothar Mueller Jul 20 '12 at 09:30
  • euh .. What's a ve-collection ? and in what way will the Navigator be different. Sorry I'am a noob ... – Marc Jonkers Jul 20 '12 at 09:52
  • "ve-collection" is my lazy-code for "viewEntryCollection" ;) - A look into the Domino Designer help file will give you some insight about the relevant Domino objects, what they are and how they are bound to view index data etc. Important reading here! – Lothar Mueller Jul 20 '12 at 10:13