I Need to prevent saved conflict in xpage - xpages

Scenario :- I opened the same document in different browsers(users). One user modified and saved the document. another user also modifying the same document which creates saved conflicts. for this I googled and found the link and tried.
http://dontpanic82.blogspot.in/2010/01/xpages-custom-control-that-can-help.html
(Thanks to Mr Tommy).
I included this custom control in another custom control(Form) at the end of Cc.
I am getting currentDocument not found in before render response event. I have my data source name document which is defined for full page not for panel.
Document handle is not getting in Before render response event?
Please help to me to solve this. or is there any other way to prevent saved conflicts?

Have a look at the concurrencyMode property of the document datasource.
You can for instance set it to fail in order for the document save to stop (fail) if a save conflict occurs. If you have (or add) a message control to your xpage, a save conflict error message will then appear.

If you isn't building for XPinc you could use my Document locker project on openntf.org
Document Locker on openntf.org
It works like this, when a user opens a document a< lock is added to an application scope bean. And when the user exits the document this lock is removed. if another user tried to enter the document at the same time they will be redirected to readmode.

Also, check the section in Mastering XPages 2nd Edition about document locking. That gives thorough examples for enabling the in-built Domino document locking.

Related

How to format link in email to open an Xpage App

I am sending out an HTML email to our users every week in which I want to include links to certain documents and then a link to the overall database. The database is an Xpage db.
On my docs I have a field only visible to me in which I compute the link I need. The format is as follows:
notes://servername/__.nsf/0/?OpenDocument
What I want is the URL to open not just a specific document, but the Xpages app in general. Everything I try opens up the all documents view.
notes://servername/__.nsf/
If I put this in the address bar, it works fine. If I put it in a link, it goes to the all documents view.
Any help would be greatly appreciated.
You could try formatting it as: notes://servername/__.nsf/nameOfXpageYouWantToOpenTo.xsp?OpenXPage
Have you set the launch properties for the database? You can specify a designated XPage in there too.
The format you are looking for is:
notes://servername/yourdb.nsf/someview/unid?OpenDocument
in the "someview" view you add a form formula to point to an empty form that has the property set "open XPage instead" - careful there are 2 of them: for web and client.
If you don't use native forms and the Xpage is always the same, then you can skip the step with the form formula and the extra form and edit the properties of the existing form.
Paul's solution should work too.
Use this code syntax to open any XPage in the Notes client:
#URLOpen("notes://Host/Path/Database.nsf/XPageName.xsp?OpenXPage")
Additional details:
And use the following to open a specific document in the XPage where unid is the unique document identifier for the document:
#URLOpen("notes://Host/Path/Database.nsf/XPageName.xsp?documentId=unid&action=openDocument")

Commenting System in XPages

I'm trying to implement a simple comment system in XPages. I have come across examples that create response documents from an existing document. The issue I'm having is when I open a new XPage and want to add a comment but I don't have an existing document because it hasn't been saved yet.
Is there a way I can create comments (response documents) on an unsaved document somehow? Or is there a different way to implement a comment system that doesn't use response documents?
Thanks for any tips.
If this is XPages then don't use a response document. Use a manual key of some sort. I prefer #Unique style keys - some people use UNIDS.
There's little to no value in using pure response document in XPages applications.
Patrick asks the key question. How can you have a "child" document if you don't first save the "parent" document.
Now of course you can save the parent and the child at the same time.
A response document need the unid of the main document for creation. If the main document is not saved you get the following exception.
Unable to create new document
NotesException: Invalid universal id
I don't know an other way to handle this problem.
Why don't you want to save the main document?
How can someone comment on something that does not exist?
I would need more details but you need to save the document. Perhaps you can move it into a different category like a draft view or something till it is ready for production?

How to prevent Lotus Notes from saving a document created by a DXL Import?

I followed this link enabling me to setup a hotspot in a richtext field - works like charm.
http://ozinisle.blogspot.de/2010/11/lotusscript-code-to-append-hotspot-to.html
Only problem is, as the user(s) usually do(es) not have deletion rights, the document created by the import stays stored in the database. In LotusScript e.g. I can create a new temporary document and work with it, and if I'm not saving it, it just disappears at the end of the function.
Is there a similar way or parameter for DXL import which allows me to just drop the document after I got my rtitem?
Alternatively, can someone point out to me if it is possible to create only the temporary richtext item in/on a document I created as tempdoc via LotusScript?
My search on the web did not get any results and my tries to reduce the linked function always resulted in the error 4518 (which is described in the help document of "DXLImporter"); if I read the help right, the DXLImporter only supports the db as valid output (thus expecting documents being created via DXL).
I don't see a way to import DXL without creating a document.
The easiest solution is to create the temporary document in users "cache.ndk". The user has definitely the right to delete documents there. So, you'd replace the line "Set db = session.CurrentDatabase" in code you linked to with
Set db = session.Getdatabase("", "cache.ndk", false)
The rest of the code would stay the same.
As an alternative, use the more classic approach running an agent on server to delete the temporary document. Create an agent which deletes the document, set property "Run on behalf of" to someone who is allowed to delete documents in database and call the agent from your script with
agent.RunOnServer(noteID)

Lotus script agent does not make any update when ran from an Embedded View in lotus notes

I have an embedded View within my form which has a bunch of agents in the embedded view.
However when i select rows(documents) in the embedded view and run the agent (eg "Do a multi profile update") it does work but it does not make any changes to the documents selected. Like the prompt in the lotus script agents does work and pop up but no updates are made.
When ran externally from the view it works fine so for some reason it does not work from an embedded view is what i feel.
The agent within the view is an Action which uses a formula language code #Command([RunAgent];"updatePeople")
were the updatePeople is a lotus script agent.
any ideas or suggestions guys?
I think you have to access the selected documents using an action in the embedded view with the LotusScript logic inside the acrtion instead of calling agents. You can find a complete answer here (with full explanation and code sample):
Domino Designer: Access selected rows from embedded view
I am not sure if this IBM TechNote explains exactly the same issue, but it seems very similar:
How to get a handle on selected documents in an embedded view when using LotusScript
Does the ID have the correct ACL settings for the agent to run?
Does the ID have the ability to edit documents?
Does the Agent have the proper save statements in the code?
The example code in the above link is doing a full db search of unprocessed documents. I would suggest using the ViewEntry document collection. This will allow the agent to run faster since the view could be customized.
Another way to go if you are having issues with processing is to set up a flag field that is updated with the save of your document. The flag field could be used in your view selection field to have the documents fall out of the view if that is desired.

Remove note's autosave functionality by adding other entity's notes on form in CRM 2011

In CRM 2011, notes get automatically created and attached to main record on lost focus event. Requirement is to remove this auto save functionality. Only till main form is open user should be able to edit notes. And newly added notes should only get saved once main form is saved. For example, if user add one note and closes the browser or do not save the main form, then that note should not get attached to main record, new note should get discarded.
I was thinking following solution:
create new custom entity TempNotesHolder
Create 1:N relationship with the entity where we want this functionality, for example Case entity
Make actual case's note section read only(it is requirement, user don't want to edit/delete functionality for notes once note get created)
Write plugin for create event of Case and create one Record for TempNotesHolder and associate it with case(RegardingId field in TempNotesHolder = incidentId) This will ensure one Case will always have only one associated TempNotesHolder record. There is no way in CRM 2011 to ensure One entity record will have only one record in associated entity i.e. 1:1 relationship. At least I don't know the way. Let me know if any one are aware about it.
On Case form, add one IFrame below Case's note section
on case form load event, get TempNotesHolderId associated with case using fetchXml.(There is no actual field in Case entity that refer to associated TempNotesHolder, hence need to use fetchXml. Some how we can add associated TempNotesHolderId to Case entity, and place that field on Case form, make it hidden, to avoid fetchXml)
Prepare url to display only notes of TempNotesHolder record.(/_controls/notes/notesdata.aspx?EnableInlineEdit=false&EnableInsert=true&id=&ParentEntity=
Set this url to newly added IFrame, so notes of associated TempNotesHolder get displayed in IFrame. It will also have link "Add New Note".
User can add note to TempNotesHolder which are not directly added to Case record.
Next develop plugin on pre save event of Case and check if there are any notes added to TempNoteHolder, if yes move those notes to Case record, and delete notes for TempNoteHolderId. This way notes will get saved to main record only on main form save.
To handle browser close event after adding few notes to TempNotesHolder, write plugin on Case pre Retrieve event, check if any notes present for associated TempNotesHolderId, if present then delete those notes. (As notes are present on TempNotesHolderId, that means due to some reason these notes are not moved to actual case record and we no longer need them, so delete them. This will ensure on case load, TempNotesHolder note section always be blank)
The above solution was fine till step 8. When I tried to add notes in TempNotesHolder, it gave me error, "Record with does not exists in TempNotesHolder". Then I checked that GUID, I disappointed to know CRM is taking IncidentId when I create note for TempNotesHolder. Then I tracked down the actual code for create notes to find why it is taking IncidentId instead of TempNotesHolderId. I found following code in "_static/_controls/notes/notes.htc" function name "UpdateNote"
xml="0"+CrmEncodeDecode.CrmXmlEncode(value)+""+_parentCrmFormSubmit.crmFormSubmitId.value+""+this.parentEntityType+""+CrmEncodeDecode.CrmXmlEncode(currentTitle)+""+this.userId+""
CRM is taking _parentCrmFormSubmit.crmFormSubmitId.value as objectid while creating note.
Now I stuck with this problem. Any thoughts to overcome this show stopper issue are appreciated. Also any other alternate solution to main requirement are also welcome.
Pravin Pujari (Microsoft Dynamics CRM 2011 Developer)
I would suggest simplifying the solution as follows:
Add a field to Case called new_notetext.
Create a Plugin against the Pre-Create and Pre-Update messages on the Case entity.
In the plugin, take anything entered into new_notetext and add a note to the Case entity using that text. Then clear the field new_notetext so nothing is saved with the record.
Should work just fine and is much simpler to implement.

Resources