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



Jul 24, 2013, 2:44 PM
30 Posts
topic has been resolvedResolved

Problem with appendDocLink method

  • Category: Server Side JavaScript
  • Platform: Mobile
  • Release: 8.5.3
  • Role:
  • Tags:
  • Replies: 9

Hello,

I have a problem, as subject says, with appendDocLink.

First, I get doc to which I want to link to:

docLink:NotesDocument  = document1.getDocument();

then,  declare variable as richtext and populate it with some info:

var info:NotesRichTextItem = ("server: " + session.getUserName()
        +  "\n" +"Database: "+ database.getFilePath());

This saves fine. Howerver, if I do 

info.appendDocLink(sessionScope.docLink);

I get error calling this metod saying I can't do that with string, altough I declared var info as RichText.

 

Anybody have a clue whats going on??

 

 

Jul 24, 2013, 5:02 PM
586 Posts
hmmm

Tomislav,

I think there's a small misunderstanding that you're having.

"var info:NotesRichTextItem = ..."

The colon and Object Type name ":NotesRichTextItem" does NOT declare info as a RichTextItem.  All the ":ObjectType" syntax does is tell the editor what to use for type ahead.  That's it.  Nothing else as far as I know.  It's just a help for the editor and is not required at all.

I think you're going to need something like:

 

var rtitem:NotesRichTextItem = doc.createRichTextItem("Body");

Which is detailed in the wiki help here:  http://www-10.lotus.com/ldd/ddwiki.nsf/dx/NotesDocument_sample_JavaScript_code_for_XPages#createRichTextItem

 

Good luck!

 

Dave

Jul 25, 2013, 9:24 AM
30 Posts
I'm a noob :(

Hello David,  did as you suggested, but.... :it doesn't work.

 

 I created helper function:

 

 function RThelper () {
   	var docRT:NotesDocument = database.createDocument();
        var rtitem:NotesRichTextItem = docRT.createRichTextItem("TEMP");
        sessionScope.info = rtitem.appendDocLink(sessionScope.docLink, "LINK");
        docRT.save();
        return  sessionScope.info;
 

But I get error sayng  sessionScope.info is null. Really confused...

 

If I try to get  my existing rich text field into var with getItemValue

I get: error calling appendDocLink for object java.util.Vector

Jul 25, 2013, 12:45 PM
586 Posts
hmmm

Do you know LotusScript. I often found that writing out what you want to do in Lotuscript is helpful to then translate it to SSJS.  Since it is similar when you're working with the Domino Object Model.

First I guess I should ask... is this solely an xpages application?  or is the notes client involved.  I'm going to assume that the notes client is involved otherwise I'm not sure why a true doclink is needed rather then manually building a url link.  If it's a pure Web application then you probably don't want to use RichText at all, The web is all about MIME I THINK.

I've not done a lot with Rich text in XPages, and certainly never tried creating a doclink. Though this should be doable I guess but I'd have to try it.  Instead of doing that as I don't have my designer handy, I'll through out some ideas and discussions points...

I'm not sure where you're calling this from.... Is this a button?  is it happening on querySave?  This code looks a fair bit different the the first one you posted. 

I'm not sure why this is a function.  Don't get me wrong I like functions, but you're not passing anything in, and there's in issue with what you're attempting to pass back.

Here's the function you pasted with line numbers:

 

1: function RThelper () {
2:  	var docRT:NotesDocument = database.createDocument();
3:     var rtitem:NotesRichTextItem = docRT.createRichTextItem("TEMP");
4:     sessionScope.info = rtitem.appendDocLink(sessionScope.docLink, "LINK");
5:     docRT.save();
6:     return  sessionScope.info;

I think one if your big issues is understanding scoped variables better.  Typically you never, NEVER put a domino object like a "doc". or "item" or anything into a scoped variable.  They're just not for that.  You seem to really want to do that so I'd focus there.  scoped variables are for strings, and numbers, and even full blown java objects but NOT domino objects. 

 

Line 1.  Nothing wrong here...  but functions should be reusable typically.  So it COULD  look something like this:

function RThelper (doc1:NotesDocument, doc2:NotesDocument) {

so MAYBE you want to just pass both documents into the function for it to do the work.  you can get a handle on the documents if they are either bound to the xpage or the code that calls the function gets it via the domino object model...  just like in lotusscript...  "getFirstDocument()"...  whatever...

Line 2... you've made a new document from the global database object.  nothing wrong there really.

Line 3... still good...  you now make a var for the rtitem

Line 4... ok.  here it goes off track a bit I think...  this assumes you have a docLink already in scope...  that's looking for an actual notesdocument though and you don't want to put that into scope.  In lotusScript the lines might be something like this:

 

Call rtitem.AppendDocLink( db, db.Title )

in SSJS MAYBE... and I'm guessing here but Maybe it should look like this:

rtitem.appenddocLink(doc2, "LINK")

so no need to assign that to a variable and certainly no need to try and assign that to something in scope....  that will just ruin your day.  :)

Line 5... that looks good.  that's how you save a doc called docRT...  though sometimes you need something like docRT.save(true, true) or whatever... HOWEVER, this goes back to where you're calling this code from...  since you're saving it here you want to make sure you're not creating a rep conflict or something if you're actually calling it from a save event...

Line 6.  this is unneeded...  there really isn't anything to return so it could be just "return" with nothing else....  you never want to return something from sessionScope I don't think because you can always access sessionScope from any code blog....  it's just available..  so once sessionScope gets set, any where later I can access it...  I THINK you're meaning for "info" to be a notesDocument?  I'm not sure.

So let's look at this in pseudo code...  let's say we have a simple button and you're using ssjs onclick...  MAYBE what you would do is something like this...

<xp:button>

// inside the click event

// assume that document1 is currently bound to the page and available globally.

// So you need to get the document you want to link to - maybe you have the UNID of that document...  UNIDS go into scope nicely

linkDoc:NotesDocument = database.getDocumentByUniversalID(sessionScope.get("linkUNID"));

// so in theory we have the current doc and the doc to append to... BUT current Doc is NOT a notesdocument but a notesXSPDocument

var workingDoc:NotesDocument = document1.getdocument()  // not sure if true is needed or not

// so now workingDoc is an actual notesDocument and not a NotesXSPDocument.  NotesXSPDocument is like a wrapper for convenience...

var rtitem:NotesRichTextItem = workingDoc.createRichTextItem("body")  // or whatever the fieldname is...

rtitem.appendDocLink(linkDoc, "LINK")

workingDoc.save(true, true)

</xp:button>

 

Anyway - sorry I couldn't give you a definitive answer but hopefully there is value in the explanation.  Just keep in mind that I don't know what you're trying to do... I'm not an expert... so I could be wrong in some of my assumptions.

 

Dave

There's a relevant question on StackOverFlow...

http://stackoverflow.com/questions/9332837/getting-an-error-message-when-trying-to-appenddoclink-is-ssjs

Jul 25, 2013, 1:10 PM
30 Posts
explanation

Thanks for the explanation David, I really appreciate it. However, I am obliged some explanaton on how the app works.

1. Every time user clicks details for document, that event needs to be logged. Lets call that document :doc1.

2. Log is legacy notes application, which has 1 field that is rich text. That field contains all sorts of informaton, but one that is bugging me is link to doc1, which is only one of informaton stored in that rich text field. I want to append it to text I stringed before.

3. So I want to put link to doc1 inside rich text, along with other info I get. For this I save to another document, doc2, which adds another layer of complexity.

4. For that I made SSJS library, because I tought it was good idea to have my app logic and my logging logic separated. Its all in the same database.

5. Finnaly, here is picture of my problematic rich text field, and how it should look like. Its basicly piece of view on doc2 ( log of reading doc1):

http://tinypic.com/r/rsh0kp/5

I get and save rest of information fine but clickable link is whats the problem.

Hope this makas more sense, and sorry for the confusion

 

Also, I'm thinking to abandon appendDocLink, as it seems to complex for my stage of xpages knowledge (and 0 LS knowledge :(  )
DO you think its possible to get link to notes doc using getNotesUrl and then append that to rich text field, but to show as clickable link??

Jul 25, 2013, 1:49 PM
586 Posts
wow

Tomislav,

You do NOT know lotusscript?  you're completely new to domino and starting with XPages?  Cool!  I'd be interested in hearing more about that.

Ok so you are dealing with a client application...  good.  makes sense then.  the structure of the code I gave you should be relatively close to what you need I think...  but you're creating new documents... so I'd have a function that you pass in the current document only. "doc1"..  create the log document...  I assume this log doc lives in a different database... as in not the current database.  so you will need something like this I'd think:

 

var logDB:NotesDatabase = session.getDatabase(session.getServerName(),"folderIfNeeded\\logdb.nsf",false);

 

then in the pseudo function I gave create your new doc off that...  make sure you set the form field to be whatever form it's called.. let's try some more ROUGH pseudo code

 

function logEvent(doc1:NotesDocument) {

   var logDB:NotesDatbase = session.getDatabase(session.getServerName(), "logDB.nsf")  // assuming no folder

   var logDoc:NotesDocument = database.createDocument()

   var rtitem:NotesRichTextItem = logDoc.createRichTextItem("TEMP");  // assuming TEMP is the field name

     rtitem.appendDocLink(doc1, "LINK");  // First just append the doclink..  get that working.. then mess with other stuff in the field

  logDoc.replaceItemValue("form", "formName"); // This might not be needed if you have only 1 form in the logdb... but good practice
     logDoc.save(true, true)

}

 

Again  that was quick and rough...  

 

AppendDoc link is not too complex here... shouldn't be at least... however...  an alternative since it looks like you're storing the UNID of the original document is to modify your log form... with a button or action hotspot or something to open the document from that... there you would use LotusScript...  you'd need the unid...  you'd use the object to get a handle on the original doc... and then open it with NotesUIDocument...

 

Set notesUIDocument = notesUIWorkspace.EditDocument( [editMode [, notesDocument [, notesDocumentReadOnly]]] )

 

At this stage I'd suggest not doing that and trying to get your doclink to work first.  

Jul 25, 2013, 2:51 PM
30 Posts
desperate...

David,

for 2 days i'm struggling with this.....my head hurts :(

 

So maybe if you can show it to me as simply as possible.....

 

i have this:

var info = ("server: " + session.getUserName()
                +  "\n" + "Document link: ");

document2.setValue("LogDocInfo", info); // LogDocInfo is rich text field on form, but my var info is not

document2.save();

This saves normally...however, as info is not rich text, i cannot append doc.

appendDocLink works, but only if I apply it to ANOTHER document which I create . With method you described. Maybe the key is to know  elements of Rich Text ,

 so I coudl do somethnig like:

document2.createRichTextItem("XXXXX"); , but what to put in place of XXXX???? Tried LogDocInfo, but it doesn't work

 

this is existing lotus script code for that:

Dim rtitem As New NotesRichTextItem(logDoc, "LogDocInfo")
            Call rtitem.AppendStyle( gRtStyle )

' Set custom Property
            Call SetDocInfo(logDoc , doc )
            
            'Dim rtitem As New NotesRichTextItem(logDoc, "LogDocInfo")
            rtitem.AppendText("Dokument:")
            rtitem.AddNewline(1)
            rtitem.AppendText("Server: "  & globalTab & doc.ParentDatabase.Server)
            rtitem.AddNewline(1)
            rtitem.AppendText("Database: "  & global1Tab & doc.ParentDatabase.FilePath)
            rtitem.AddNewline(1)
            rtitem.AppendText("UNID: "  & globalTab & doc.UniversalID)
            rtitem.AddNewline(1)
            rtitem.AppendText("Note ID: "  & globalTab & doc.NoteID)
            rtitem.AddNewline(1)
            rtitem.AppendText("DocLink: "  & globalTab)
            Call rtitem.AppendDocLink(doc, doc.UniversalID)

 

I dont know how to read it, let alone how to rewrite it to javascript.

I understand if you give up on me, I would give up on myself if I could.....

Jul 25, 2013, 6:11 PM
586 Posts
Some code

 

I took a couple of minutes and made a logDB...  though in a form with a rich text field...  as well as another one for the key of it...

I want to an xpages application and opened a document...  I created a new button that uses this code in the click event.  I didn't do the function thing...  just a quick test.

This code (at the bottom) works...  If makes a document in the log database...  it appends text and the doclink to the richtext field on that form.  The doc link works.

 

Don't try and put your docLink into a scope or even javascript varible like you did here:

var info = ("server: " + session.getUserName()
                +  "\n" + "Document link: ");

Use the methods of the richtextitem...  to add your text...  and newline...

 

See if that helps..

 

var logDB:NotesDatbase = session.getDatabase(session.getServerName(), "logDB.nsf")

var logDoc:NotesDocument = logDB.createDocument()

var rtitem:NotesRichTextItem = logDoc.createRichTextItem("Body");

rtitem.appendText("Here is some text");

rtitem.addNewLine(2);

rtitem.appendDocLink(authorDoc.getDocument(), "Original Document");  // make sure you use the getDocument() here

logDoc.replaceItemValue("form", "log"); 

logDoc.replaceItemValue("field1", "something"); 

logDoc.save(true, true)

Jul 26, 2013, 9:12 AM
30 Posts
great success!

David,

I menaged to do it. The problem was (I think),  that I  tried to append to NotesXspDocument,  when  should have worked with Domino Document.

And I menaged to put it all into SSJS script library, because I call log from lot of different places, so its more practical that way. All works fine :)

I'm still pretty new to all this, but I'm learning more every day and your help has been invaluable.

Thank you very much!!

Jul 26, 2013, 5:55 PM
586 Posts
Cool

glad you got it working!!

Yeah...  NotesXSPDocument can bite you...  it's similar in concept to NotesUIWorkspace in LotusScript I guess...  at least that's how I think of it.

 

Great Job!!


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