How to get HTML content out of Richtext field of Notesdocument - xpages

enter image description hereHi In My Xpages application, I would like to take reference of HTML stored in NotesDocument richtext field( Cofiguration document in Notes Client ), so in Xpages data source I mentioned configDoc as source as Notes Domino Document and in Default Action I set it to " Open Document" and in Document id " I set Computed value as below"
var vw:NotesView = database.getView("vwConfig")
var doc:NotesDocument = vw.getFirstDocument()
var uniid:String = doc.getUniversalID();
return uniid
In one of the place I placed on computedField property, I mentioned ssjs code as
return configDoc.getValue("RTFIeldasHTML").getHTML();
this works if I open document but does not work if I open existing document and it gives me an error:
Error while executing JavaScript computed expression
docConfig.getValue()' is null

Most likely cause is docConfig doesn't have ignoreRequestParams="true". That means it's opening the document whose ID is in the URL and ignore anything you put in the documentId property. Set that and it will work correctly.

Related

beforePageLoad failing when a view column is computed

I've got a view control which opens an xpage. When the xpage opens, the beforePageLoad event fires. It checks to see if there are any attachments in a particular field of the document being opened and if there are, it returns list of the filenames. This was working fine. Then, I was asked to change what's displayed in one of the columns of the view. I added a variable to the view control's data section to access the row. I then added some javascript to the column to display the data differently. That worked and it displayed the data as wanted. However, when I now click on the link to open the xpage, when the beforePageLoad event fires, the code that's there now fails. It fails with this error at the starred line:
Script interpreter error, line=9, col=49: 'closureField' is null at
[/Function_ReturnListOfClosureAttachmentNames.jss].ReturnListOfClosureAttachmentNames(CCEB1351591847CB85257E7C005EF68C)
function ReturnListOfClosureAttachmentNames(ltDoc ){
var closureAttachmentFileNames = "";
var thisLT = ltDoc;
var closureField:NotesRichTextItem = thisLT.getFirstItem("closeAttachments");
*>>> var eos:java.util.Vector = closureField.getEmbeddedObjects();<<<
var eosi:java.util.Iterator = eos.iterator();
while (eosi.hasNext()) {
var eo:NotesEmbeddedObject = eosi.next();
closureAttachmentFileNames = closureAttachmentFileNames +","+eo.getName();
}
return closureAttachmentFileNames;
}
I call this function from the beforePageLoad event and pass it currentDocument.getDocument(). I think I might have lost the document context after changing the column display data from 'view column' to 'computed value' but I'm not sure. Any ideas would be appreciated.
thanks!
Clem
Figured it out: When I assigned a variable to the view, when you click on a linked column in that view, it loads the current ViewEntry into the context and not a current document. So I put the unid of the doc from the selected ViewEntry in an application scope variable and returned it to the Document Id property when I open the xPage. I have to now update all my views but there aren't too many luckily. Thanks for working through this with me!
Clem –

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

Setting a document field with replaceItemValue from a rich text control?

How do you set a richText value with replaceItemValue from a rich tect control?
I found this bit of code here:
http://www.bleedyellow.com/blogs/martin/entry/save_a_richtext_field_from_a_xpage_to_a_document?lang=en_us
var doc = configuratieformulieren.getDocumentByKey("ConfiguratieIVNL", true);
if(doc == null){
return;
}else{
var titel = getComponent("inputTextIBPTitelIVNL").getValue();
doc.replaceItemValue("IBPTitel",titel);
var inhoud = getComponent("inputRichTextIBPInhoudIVNL").getValue();
if (inhoud != null){
var contentType = doc.getMIMEEntity("IBPInhoud").getContentType();
var encoding = doc.getMIMEEntity("IBPInhoud").getEncoding();
var str = session.createStream();
inhoud.toString();
str.writeText(inhoud.toString());
doc.getMIMEEntity("IBPInhoud").setContentFromText(str, contentType, encoding);
}
doc.save(true, true);
}
sessionScope.put("FormulierIVNLInfoBeschPG","Lezen");
Is it correct? It looks like this code depends on the fact that the field already exists. How id this handled if the field does not exist? Is there and easier way to set a field value to the contents of a rich text control?
Let data sources do the heavy lifting. For a long and boring (but thorough) explanation of why, read this article. But here's the quick version:
Don't use:
getComponent("someID").getValue()
Instead, use:
someDataSource.getValue("someFieldName")
This is always a more efficient way to access data: instead of having to spider through the component tree to locate a match, it goes straight to the data source, which the component would have to ask anyway if you asked it what its value is.
Similarly, don't use:
someDataSource.replaceItemValue("someFieldName", someValue)
Instead, use:
someDataSource.setValue("someFieldName", someValue)
The latter is much more flexible on input type. The data source already contains all the logic for determining what to do based on whether the value is text, date, number, rich text, file upload, etc. No need to duplicate any of that logic in your own code.
So if the goal is to update a separate document based on data in the current document, just define a separate document data source that points to the document you want to update. Then it's literally this simple:
configData.setValue("RichTextData", currentDocument.getValue("RichTextData"));
configData.save();
With the above code, if the field you specify on the current document is rich text, then the item it creates on the other document will be rich text. If it's any other type on the current document, it will be the same type on the other document. With getValue() and setValue(), you don't have to pay attention to the data type... the data source handles all of that for you.
For bonus points, scope configData to applicationScope so that any updates to it are immediately cached for all users... or sessionScope if the document you're updating is user-specific.
I was able to solve my orginal issue. To expand on my issue I was having problems with using a dialog box to create Form / Document B from Form / Document A using a dialog box on Form A. What was happening was any changes to Form B would be saved to Document A's datasource.
I found the ingoreRequestParams on Form B's datasource, set it and that solved my problem with Form B writing to Form A document.

How to set the pageTitle property for all pages that use a custom control?

Would like to automatically compute the pageTitle property on the XPage to simply show the XPage name. I want to code this once on the Application Layout custom control so every page where I add the control gets the benefit of the property calculation. So far, I have some SSJS on my CC to calculate the page title and assign to a viewScope variable:
var path:String = context.getUrl().getPath();
var xpageName:String = #RightBack(path,"/");
viewScope.xpageName = xpageName;
return xpageName
On any XPage where I add the CC I can simply return the value of the viewScope variable to the pageTitle property like this:
viewScope.xpageName
However, was wondering how to automatically set it from the CC without the need for the line above. Can this be done?
You can also set the pageTitle in a theme. This page from Julian Buss's site shows code for defaulting the value http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/Work_with_themes. Because override is set to false, you can override it on any custom control or XPage you choose. This is one of the theme properties I set in all applications.
You can do this as Declan says in the All Properties property on the Custom Control. I prefer to put this in the Database Theme using a control block like this:
<control override="true">
<name>ViewRoot</name>
<property>
<name>pageTitle</name>
<value>#{javascript:
var path:String = context.getUrl().getPath();
var xpageName:String = #RightBack(path,"/");
viewScope.xpageName = xpageName;
return xpageName
}</value>
</property>
</control>
This then forces your code to use the ssjs code for all XPages delivered in the database. I actually prefer that the return value be:
return database.getTitle() + " : " + xpageName;
Enjoy
/Newbs
In the 'All Properties' panel of the custom control there is a 'pageTitle' property that you can use. Once set it will be used for the title of the page as long as there is no pageTitle property set on the main XPage and as long as no other custom control on the same page have the property set.

XPAGES: Link name using getelementbyid

How can I get the label of the link that is clicked by the user?
I have tried:
var elem=document.getElementById("#{id:link1}");var lbl=elem.label;
But this is not returning the label name.
The "label" property of a Link control is called text so the following server-side Javascript will get you the value of the label of the link and store the value in the variable "label":
var linkControl = getComponent("linkExample");
var label = linkControl.getText();
In Xpages [xp:label] tags turn into [span] tags so on csjs you have to use the innerHTML to get the value so your original code would have worked had it been.
var elem=document.getElementById("#{id:link1}");
var lbl=elem.innerHTML;

Resources