1

I followed How do you copy a datetime field from the current document to a new document and I try something like this:

Cdoc.save();
Pdoc.copyItem(Cdoc.getDocument().getFirstItem("mytest1"));
getComponent('exampleDialog').show()

But I get a handling error message.

Thanks for your time!

Community
  • 1
  • 1
Florin M.
  • 2,159
  • 4
  • 39
  • 97
  • 1
    And what does the error message say? – Per Henrik Lausten Jun 18 '14 at 07:56
  • 500 Error: Error 500 HTTP Web Server: Command Not Handled Exception – Florin M. Jun 18 '14 at 08:02
  • 1
    Yes, but what does the error say in the XPages log file? Use XPages Log File Reader from OpenNTF to get easy access to the XPages log files. The XPages log file contains the details behind the error message. – Per Henrik Lausten Jun 18 '14 at 08:09
  • I'd recommend enabling the option to display the XPages runtime error page while developing, so you can see more details of why it's failing. Better still is to add a custom error page so users will not get an Error 500 page and you can see the error yourself. Even better is using XPages OpenLog Logger from OpenNTF, which will log errors for uncaught exceptions like this (see documentation for the need for a custom error page) – Paul Stephen Withers Jun 18 '14 at 09:46

2 Answers2

1

Assuming Cdoc and Pdoc are defined as xp:dominoDocument data sources then you have to change your code to:

Cdoc.save();
Pdoc.getDocument().copyItem(Cdoc.getDocument().getFirstItem("mytest1"));
getComponent('exampleDialog').show()

So, you only need to add .getDocument() to Pdoc to get the Notes Document. Otherwise it fails and you get the error "Error calling method 'copyItem(lotus.domino.local.Item)' on an object of type 'NotesXspDocument'".

Keep in mind that you have to save Pdoc after copying item too if you want to show the copied item in your exampleDialog.

If you don't want to save document Pdoc at this point yet then you can copy the item on NotesXspDocument level with just:

Pdoc.replaceItemValue("mytest1", Cdoc.getItemValueDateTime("mytest1"));
getComponent('exampleDialog').show()
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Thanks @Knut for your answer. I still get a 500 Error HTTP Web Server. I might use then xpages log file reader then, to find out what's wrong with the code. In my case: Cdoc and Pdoc are two datasources. – Florin M. Jun 19 '14 at 05:11
  • Open Application Properties, click on XPages tab and switch on "Display XPage runtime error page". Then you'll see the error message. – Knut Herrmann Jun 19 '14 at 05:18
  • [ReferenceError] 'Pdoc' not found . The dialog that later I want to show contains some fields which are binded to Pdoc'fields. This dialog is on a custom control, which lays on a XPage. – Florin M. Jun 19 '14 at 05:21
  • It should work with custom control too. Did you add `Pdoc.save()` as third line already as I mentioned in my answer? – Knut Herrmann Jun 19 '14 at 05:27
  • yes, but still: 'Pdoc' not found. Regarding Pdoc.save(): My dialog contains the structure of a form, with 2 buttons : Save and Cancel. If I already save 'Pdoc' before I show the dialog, then the Cancel button should delete the current already saved Pdoc, right? – Florin M. Jun 19 '14 at 05:31
  • How did you define Pdoc? – Knut Herrmann Jun 19 '14 at 05:35
  • I defined inside the custom control which contains the dialog. – Florin M. Jun 19 '14 at 05:41
  • No, that doesn't work. You have it to define data source Pdoc in XPages or cutom control where you have the button and the dialog custom control is embedded. – Knut Herrmann Jun 19 '14 at 05:44
  • So the dialog must be in a custom control which is on the same xpage with the button? – Florin M. Jun 19 '14 at 05:44
  • No, the data source definition has to be in level where it is first used. The embedded custom controls have then all access to it. – Knut Herrmann Jun 19 '14 at 05:46
  • It works. Thank you... But it is strange that the Pdoc ( the dialog ) must be saved before the dialog is showed.... What it happens if I do not want to save my data from my dialog? – Florin M. Jun 19 '14 at 05:52
  • I updated my answer for the case you don't want to save Pdoc before calling dialog box. – Knut Herrmann Jun 19 '14 at 05:53
  • I now noticed that the mytest1 from the Dialog was binded to Cdoc, too. Not to Pdoc. When I changed to be binded to Pdoc - with the same name field from that datasource, isn't working anymore. ;( – Florin M. Jun 19 '14 at 06:03
  • Hmm, to answer your question I created an example like yours and it works for me. What do you mean by "isn't working anymore"? – Knut Herrmann Jun 19 '14 at 06:08
  • My code: Pdoc.replaceItemValue("txt_NC", Cdoc.getItemValueDateTime("txt_NC")); getComponent('exampleDialog').show() // with txt_NC - the name of field from the two datasources. It is the same name. – Florin M. Jun 19 '14 at 06:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55887/discussion-between-knut-herrmann-and-mfg-flay). – Knut Herrmann Jun 19 '14 at 06:10
0

I do not often use "copyItem". You are not specifying if you are using NotesDocuments or NotesXspDocuments, so I will write a quick thing about both because they should be handled differently.

var currentDoc:NotesDocument = ....
var newDoc:NotesDocument= ...

newDoc.replaceItemValue("fldname", currentDoc.getItemValueDateTimeArray("fldname").elementAt(0)) 

if currentDoc is a NotesXspDocument, use the following

var currentDoc:NotesXspDocument = ...
var newDoc:NotesDocument=...
newDoc.replaceItemValue("fldname", currentDoc.getItemValueDateTime("fldname"))

Otherwise, you could continue trying with copyItem, I just lack experience with it.

EDIT
Just some things to add, remember that putting calling xspDoc.getDocument(true) will update the background document and this might be needed. Also, in the comments for that article you posted, they mentioned the possible need to put that document into another variable.

var docSource:NotesDocument = xspDoc.getDocument(true);
var docNew:NotesDocument = ...
docNew.copyItem(docSource.getItem("blah"); 

Also remember that copyItem is a function of NotesDocument and not NotesXspDocument.

Greg
  • 714
  • 4
  • 16
  • Is it possible newDoc to be also a NotesXspDocument ? – Florin M. Jun 18 '14 at 08:25
  • absolutely. the code would be the same in either case, that is why I did not include it. There is no difference between NotesDocument.replaceItemValue and NotesXspDocument.replaceItemValue. – Greg Jun 18 '14 at 08:26