This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Apr 8, 2012, 6:56 PM
68 Posts
topic has been resolvedResolved

Removing related documents.

  • Category: Documentation
  • Platform: All
  • Release: 8.5.3
  • Role: Administrator
  • Tags: Delete,Relations,Delete relations
  • Replies: 7
Hi Guys,
 
At Beginning I want to say that I'm pretty new in XPage's  and that's why I'm looking for your page. I have "datasable" looking something like this:
 
http://dl.dropbox.com/u/16887656/ibm1/1.PNG
 
 To create new "Pytanie" for example I'm using such a script:
 
var newPytanieDoc = database.createDocument();
newPytanieDoc.appendItemValue("Form", "Pytanie");
newPytanieDoc.appendItemValue("ID_Ankieta", AnkietaDocument.getNoteID());
newPytanieDoc.appendItemValue("TYP", getComponent("TrescPytania_InputText").getValue());
newPytanieDoc.save();
 
To show "Pytanie" in "Ankieta" documents I use repeat control with such formula:
 
if(!AnkietaDocument.isNewNote()){
var pytaniaView = database.getView("vPytania");
pytaniaView.refresh();
return pytaniaView.getAllDocumentsByKey(AnkietaDocument.getNoteID());
}
 
This is how it looks in designer and preview:
 
http://dl.dropbox.com/u/16887656/ibm1/2.png
 
And now is my problem. You can see there (Usuń) link control. I want to make this working but in some specific way. After clicking it it should delete all Documents in ODPOWIEDZ that have ID_Pytanie equals to value of ID_Pytanie which is Clicked. Or maybe fast and straight version. After clicking this link I want to Delete all related Documents in other form that have "clicked" ID (ID of clicked one).
 
Bonus question:
 - How to make own confirmation text formula (like in Deleting Documents) ?
Apr 8, 2012, 9:11 PM
17 Posts
Re: Removing related documents.
Hi Karol,
you can create a link with an onclick event and add two actions (in an action group):
1) confirmation text (it is one of simple actions - Basic / Confirm Action)
2) call removeAll() method of NotesDocumentCollection (action Execute Script)
 
Patrik
Apr 8, 2012, 10:04 PM
68 Posts
Re: Removing related documents.
Dear Patrik,
 
Thanks for your answer but RemoveAll(). Removes all data from certain form (translating in java language its remove all from certain table of datasable). I need method, or some trick that will remove only certain values that have certain ID. Some kind of loop that will check all ID's and remove searched. 
 
Something like (it will be example on the list):
 
ID_Pytanie = get.IDPytanie(); // Need something like this but I think that

for (i = 0; i < Pytanie.Size < i++) // Need method to get a  Document Size or some kind of special loop
{
        if(ID_Pytanie == Pytanie.get(i).IDPytanie) Pytanie.Remove(i); // And such a condition.
 
My problem is that I cant find methods to use them ... 
 
Apr 8, 2012, 10:30 PM
586 Posts
Re: Removing related documents.
 Karol,
 
 I didn't look at your screenshots but it sounds like you want to remove the documents that are related to your current document.
 
What you probably want to use is the getDocumentByKey() method to get a collection of the related documents.  Then you can just delete them. 
 
here's some PSEUDO Code... 
 
Database is a global object.... 
var key = 'ASSIGN KEY VALUE HERE'
var myView:NotesView = database.getView("relatedDocsByKey") 
collect:NotesDocumentCollection = myView.getAllDocumentsByKey(key, true) 
 
collect.remove 
 
I forget if it's collect.remove or remove all or something else so you might need to check the docs. 
 
It's possible I demonstrate some of this on my XPages.TV site.  I did a show on data relationships.  Probably doesn't show deletions but likely shows how to get items by collections... 
 
Good Luck 
Apr 9, 2012, 7:43 AM
68 Posts
Re: Removing related documents.
Hi David Leedly !
 
I must confess that I searched some kind contact to you but on your blog a profile page don't work. I watched your youtube movies and I really thanks for them. But going back to my question I tried your code but maybe I misunderstood something and thats why its not working.
 
 Code:
 
var key = pytanie.getNoteID(); // This is 100% good its took good key
var myView:NotesView = database.getView("vOdpowiedzi") // vOdpowiedzi is view where I have all Odpowiedzi (Maybe this is wrong you write relatedDocsByKey, and I don't know at all how to create related view :O)
collect:NotesDocumentCollection = myView.getAllDocumentsByKey(key, true)
collect.remove(); // This lane cause an error after deleting it simply nothing happens but still there is no error.  Tried all removeAll, delete etc.
 
Screenshot of documents (Take a look):
 
  
 Error after pressing button:
 
Error 500
HTTP Web Server: Command Not Handled Exception 
 
 
Edit 3: I tried all here is my application to test this:
 
 
the problem is in Custom Control called: ccAnkieta_Detale in (Usuń) link cotrol maybe Im blind or what but I can't make this working...
Apr 10, 2012, 3:02 PM
586 Posts
Re: Removing related documents.
 Hi!
 
Glad you like the videos.  Thanks!
 
 
 Below is some code from the help database.  I think you can safely ignore the loop as that's just populating the collection rather then getting a document by key.
 
Suggestion after you get your collection with: 
collect:NotesDocumentCollection = myView.getAllDocumentsByKey(key, true)
// Out put the collection count to the log to make sure that we have documents.
print(collect. getCount())
 collect.removeAll()
 
That really should do it.  Are you sure that you're doing it under an account that actually HAS delete access?  Is there an error message?  Don't forget to go into application properties and click on for the runtime error thing.  That should give you more detail then the Error 500.
 
Try that and see if either  of those options work.  the really should assuming you have ACL delete access.  If not I'll try and put a demo together for notesin9.com / xpages.tv.
 
Dave 
 
====  From Help DB ==== 

var dc:NotesDocumentCollection = database.createDocumentCollection();

 var view:NotesView = database.getView("main");

var doc:NotesDocument = view.getFirstDocument();

while (doc != null) {

if (doc.getItemValueString("subject").endsWithIgnoreCase("obsolete")) {

dc.addDocument(doc);

}

doc = view.getNextDocument(doc);

}

requestScope.status = "Number of documents removed: " + dc.getCount();

dc.removeAll(true); 
Apr 10, 2012, 5:23 PM
68 Posts
Re: Removing related documents.
Hi Dave one more time !
 
This works fine. Thank you very much ! Waiting on your new movies. Really thanks for your help.
Apr 10, 2012, 6:54 PM
586 Posts
Re: Removing related documents.
 Glad you got it working!!!!
 
More shows and other BIG changes coming very soon I hope.   
 
:-) 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal