Florin M.
Florin M.

Reputation: 2169

xpages copy field value to another field from other datasource

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!

Upvotes: 1

Views: 423

Answers (2)

Knut Herrmann
Knut Herrmann

Reputation: 30960

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()

Upvotes: 1

Greg
Greg

Reputation: 714

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.

Upvotes: 0

Related Questions