I got a panel which bind to an open document as data source called document1 in an extlib dialog box. On button save, I want to compare all the field values between back-end document and document1. However, all the field values from back-end document are seemed to be updated therefore their field values are the same in document1. The comparison is done before docuemnt1.save().
From my understanding, document1.getDocument() should get the back-end document which all original/current data. document1.getDocument(true) should get all new data. I had try to getDocumentByID and found that all field values are updated in back-end document. I have no idea because document1.save not yet executed.
Why back-end document being updated with new data before save?
Is there any better way to get back-end document which all original/current data?
If you are using the the parameter true with the getDocument method, all changes done to the datasource are temporarly written to the datasoure's datastore.
The XPages engine is "smart enough" to realize that multiple instances of a NotesDocument object are all referencing the same backend document. It will now return the cached data from the datasource's datastore. That is why all objects will now return the updated values instead of the values stored in the backend document (Using of multiple datasources will give you the same result).
To access the data from the backend document, you can use a #DbLookup on a view with all documents sorted by their UNID.
#DbLookup("","AllByUNID", document1.getDocument( true ).getUniversalID(), "FIELD")
Related
I am new to NodeJS, MongoDB and express.
I am able to insert, delete and update data but I dont really know how to work with it.
I want to choose some data(e.g. from a dropdown form) and then pass that data to some functions and calculate results. How is it possible to show the results to the client in the webpage(e.g. in a table)?
For example: I have different JSON objects stored in my database and now I want to select one by the name. Then do some calculations with it and show the results to the client.
Also: Is it possible to tell the Database to only accept valid JSON data?
Yes you can get specified data from the database and it will work a lot better with mongoose. You can define schema in mongoose and you can focus more on the data instead of how your data look like. And you can do validation to accept the valid data.
I filtered out XPages view with 'search' option. Then I'd like to access all of the documents by SSJS.
If I access the bound Notes view by database.getView("ViewName"), the view is not searched and could not get the searched result.
How can I access the document collection?
The dominoView data source is just a wrapper that runs calls on the underlying view to return a subset of entries to display in a view component (Data Table, View Panel, Repeat, Data View etc). Consequently, unless the rows property is set to a large enough value to get a handle on all responses, you’re unlikely to be able to access what you want that way.
The best approach will be to run the search on the backend view in SSJS / Java.
See https://www.intec.co.uk/understanding-xpages-views/ for a more detailed explanation of the different elements involved and their inter-relationships.
I'd like to use a view to compute a summary of bigger documents.
Every document produced by the view corresponds to one source document.
The view output is used to populate table in the UI, clicking a row of the table opens the bigger document.
When there's a conflict in the underlying document I'd like to show it in the table row, so user can open the full document and resolve the conflict.
How can I efficiently obtain the conflicts to show in the table? (all the conflicts for the underlying docs)
Thanks
You can use the conflicts option in the view parameters, together with include_docs. You can find more info about view params in the CouchDB docs.
E.g. http://localhost:5984/mydatabase/_design/documents/_view/posts?conflicts=true&include_docs=true adds the property _conflicts to each document that has a conflict.
Pro tip: In that case you don't need to emit the whole document in the view itself, as the include_docs parameter returns the complete document anyway.
Another possibility is to emit the _conflicts property itself. You can do that like this:
function (doc) {
if (doc._conflicts) emit(doc._id, doc._conflicts);
}
This is a handy view for finding only documents with conflicts.
I have two forms project(Document) and comment(Response to Response) I want to create a view that displays all comments of selected Project
Any help would be appreciated.
I love doing this type of stuff in xPages.
For a moment, don't think about project and response. Think uniqueID. In order to make the project document reference the comment you add a unique ID to each of them that will reference each other. Don't use response docs in xPages, there is no need I see. When you save the comment, save the unique ID of the parent document to a field on the comment document by referencing this value where document1 is the datasource of the parent and document3 is the document of the child.
<xp:modifyField name="uid"
value="#{javascript:document1.getDocument().getUniversalID()}"
var="document3">
</xp:modifyField>
Now that you have a bunch of parent and children docs, you create a categorized view where you are only capturing the comments. Use a view selection formula to exclude the parent form. Make the first column the uniqueID that you previously captured. You now have a view that will keep all the comments categorized by the unique id of the parent.
Now in the xpage you now need to filter on the key value. You filter by computing the keys to the value of the parent document. Here document1 is the parent.
<xp:dominoView var="view2" viewName="rejections"
keys="#{javascript:document1.getDocument().getUniversalID()}">
</xp:dominoView>
The great thing about doing this is it will work in a viewPanel, dataView, or a repeat control since you are referencing the data not the UI.
If you wanted to do comments of comments there are a couple of approaches but I think they would all have the same structure. If you made it this far start looking at repeat controls they will let you break free of the normal notes views.
I moved away from using Parent and response documents in Notes years ago because they were just too much trouble. I also moved away fro using the UNID as the 'link' for several reasons. The first is that the UNID can change (resolve a save/rep conflict) Second archiving is all but impossible because again the UNID changes when the document is copied to another DB. So when I create a 'parent' document I store #Unique into a field I call LinkKey, and store that value in all 'response' documents. When I create the response then I store a new #Unique into a field rLinkKey. This way a response to a response knows it's originator (LinkKey) and it's direct parent (rLinKey). Now you can extend this any number of levels deep fairly easily.
This worked OK in native Notes with some kludge, but now in XPages with repeat controls the real power comes from nested Repeat Control. Something I have always wanted to do in Notes but was never able to is now a piece of cake.
The down side is that getDocumentByUNID() is going to be faster that getDocumentByKey(LinkKey, true) but the other advantages far out weigh the unnoticeable time difference (IMHO)
I want a metadata field getting values from database record. This metadata field should be added to document.
Can anyone provide a solution to my requirement.??
I presume you are using Liferay 6.1.
Web Content Structures
As for Web Content, you could programmatically create a JournalStructure (see JournalStuctureLocalServiceUtil) and populate the list of possible values for your structure field with values coming out of the database. You can put this "import code" inside a batch job, so your structure field and the values inside the external database are always in sync.
Document Metadata
How to do this with Metadata Sets is probably more interesting, as not only Dynamic Data Lists and Documents & Media use this in Liferay 6.1; as of 6.2, Web Content structures will utilize the same metadata API in favor of the old Journal API.
For this to implement, check out the xsd column of the DDMStructure table. It has more or less the same format as the XML for a JournalStructure, however there are more options available. Use DDMStructureLocalServiceUtil#addStructure to add such a new structure. Again, run this inside a batch so you always have the latest external DB values.