Xpages dropdown menu resubmission on SSJS submission using submit value property - xpages

Just for reference before mentioning the problem I would like to say that I have asked to same question on IBM Lotus forum(http://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=2AD7C8F89D8930E685257BD50022A9E9) and I have not received any reply for the same in last 2 weeks.
So, I have a typical xpage dropdown menu with say around 40-50 leaf nodes, Every leaf node submits a specific value (using submitValue property) which is then evaluated and action is performed. However, the problem is that, after the action is performed if I try to refresh the page i get the browser notification for re-submission (I believe that it is some kind of programming error by me, however I don't know how to resolve it.)
One example to make it more clear:
I have a delete node inside the dropdown. It basically deletes the selected entries from the view(generated using repeat control) and then refreshes the view content. But at this point of time if I try to refresh the page then I get the notification of re-submission by the browser. If I accept it, then it tries to delete it again (which I prevent it but still this shouldn't happen) and if I don't accept it, it just doesn't refresh the page.
Any reply would be appreciated.
Thank you in advance. Hoping to hear some suggestions. (Please let me know if event he code is required)

I believe you need to implement the Post/Redirect/Get pattern to avoid re-posting on refresh.
Here's a solution by Tommy Valand for XPages for that pattern: http://dontpanic82.blogspot.dk/2010/06/xpages-avoid-saving-duplicate-documents.html

Related

Kentico Form - Edit Form Action and Field Names

I have a form built in Kentico and want to change the form action to point to a marketing automation vendor website (eloqua) to process the form. I noticed that there's no way to change the Action on the Form app, so I thought of using js to replace the action dynamically. I'm not sure whether it'll work, but another immediate problem I have is the field name/id generated by Kentico is so long (> 70 characters - e.g. p$lt$ctl02$pageplaceholder$p$lt$ctl03$On_lineForm$viewBiz$Company$txtText) and exceeds the length allowed by the vendor. Is there a way to shorten those names/ids?
To clarify, the reason I need to edit the name because the vendor allows to map (copy/paste) html name to whatever name it's using. I've tried pasting the whole string from one Kentico field and got the error message of exceeding character limit.
First part of the question, how do i direct a form to submit to another site?
In ASP.Net, the only way is to use javascript to alter the 's action url. Since you want to be careful where you edit this, i would use jQuery to replace the "Submit" button on your form with a javascript function that will alter the form before submission (so you don't mess up other postbacks)
$("button.MySubmitButton").click(function() {
$("form").attr("action", "http://TheVendor.com/PostLocation");
});
Next question is to alter the field names. If you absolutely MUST have form element IDs sub 70 characters, you will have to use Javascript again and it will break any postback-related functionality of the elements, so make sure the form is "as is" before doing it.
Again there is security concern because when you post to another location, you are sending ALL the data, including hidden asp.net inputs that contain viewstates and the like. You may want to take the time to 'eliminate' right before you submit any field that you don't want sent to the other site.
Something like this (Test it out a bit first though)
$("input:not(id*='txtName'):not(id*='txtEmail'),select:not(id*='ddlQuestion')").remove();
As #trevor-j-fayas points out, you can use javascript to point a form action to another url. While this does work you may end up writing a lot of javascript to not only point the form to a new url but also to do some data massaging (changing id's, doing url formatting, etc) before sending it to the target.
Additionally you lose some of the benefits of using a Kentico Form because the data never actually gets submitted back to Kentico such as email alerts.
I have worked in a similar scenario where were we sending data to Eloqua but instead of doing it client side we did it from the server by using either:
The OnOnAfterSave event on the BizForm control itself
The global BizForm submit hook BizFormInfo.TYPEINFO.Events.Insert.After
After the form is submitted to Kentico, our custom hook code runs which sends the data to Eloqua. In either hook you can fully access the Form metadata, field names, and submitted values. You can then craft an HTTP POST request and submit it asynchronously using a class such as HttpClient.
Is not a good idea from the architecture stand point and most likely not going to work without opening a huge hole in their vendor web site security. First of all how are they going to process the from if they don't know the field names, what if form fields change etc. Secondly you going to run into hell of trouble trying to submit form one site to another etc. What if the vendor site is not responding etc.
What you need to do is submit the form back to kentico web site i.e. process it on kentico web site and send email notification with results to marketing automation vendor website (the easy way for now) and redirect user to vendor web site.
Redirection and email - you can do out of the box without any programming. Actually to do all the above requires no programming and you get all the information recorded on your Kentico site.

runWithDocumentContext:passing data back to the xpage

I was playing around with run With Document Context almost the whole day. Maybe someone can help to find me a feasible solution.
If i run the agent in before page load / before render response / query Open Document event i am able to pass values back to the xpage without saving the document. I tried also to save the document but it didnt help.
Beside these two events i didn't find a way to call the agent and bring the values from the lotus notes agent back. Can anybody think of an event that would work?
Calling an agent does work from anywhere you can call SSJS. Some considerations are on my blog.
However there is one big, big caveat: when you try to use a document (saved or unsaved) that is bound to a datasource in your current XPage, then the values in the datasource will overwrite the changes in the backend document. This could be your issue?
As David suggests: use SSJS & Java. It is less work than you might fear and you can pay down some technical debt
How about just creating a new Domino document, put the fields on it that you want to send, call your agent, and then get back those fields. Then populate whatever you need to on the XPage (getComponent("name").setValue(value).
There is no need to save this temporary document and it will just end up going away when your code runs.

getDocument() from a XSPDocument is null randomly

In a production application that I have developed sometimes I get an error saying .getDocument() is null. I have added checks in my code that traps an error if this happens. And the strange thing is that the XSPDocument seams to be OK.
Any other ideas how to debug the cause of this?
========================================================
Edit
The lower parts of the application is a simple database, create an assignment it gets status new
change the status to ongoing thru a button. Add information in text, date and numberfields, no Richtext, no attachments.
The user can switch to another xpage to send this document is an pdf attachment in an email.
The user can save the document as a draft
When they are done the click on an approve button and this button will set the status to approved. Save the document and send it as an pdf to an email adress
The problem ocurrs both on the Save button and on the approve button.
.getDocument from the xsp document is null the xspdocument.getNoteID return an ID
I can do replaceitemvalue on the xsp document.
It never happens on new documents only existing what I have seen
It feels like the comment from David that the backend doc is dropped/recycled
we experienced the same getDocument() problem recently. Finally we found a root cause: two different XPages were loaded simultaneously via iFrames. One of those XPages produced run-time error randomly, in 25% of cases. A sort of conflict in JSF model in context of single session.
solution: viewState="nostate"
not sure if it helps in your case, but this option resolved a lot of problems in our applications. It was introduced in 8.5.3. And it should be especially useful for so called XAgents.
Hard to give a hint without knowing more about everything else, but I remember having seen this as well. Just a few ideas:
Is XSPDocument.getNoteID() pointing to a valid Document if this happens?
Is it maybe pointing to a different doc than what you expected?
Could there be some kind of dynamic change of datasources going on?
Maybe some kind of timeout so that the server all of a sudden forgot who you are (in rare cases this happens to me)?
Lothar/edcom
It would be helpful to have a few more details. I assume that the document has previously been saved and it's not a new note?
You're not trying to put the actual document object inside a scoped variable are you? That would be bad as that would be pretty toxic. Without knowing more I would think this could be the case. The backend document has been garbage collected.

Web scraping from a Google Chrome extension

I've started to develop a Chrome extension to navigate and perform actions on a website. Until now the extension is able to receive a couple of parameters and check a set of radio-buttons, fill in a few inputs of a form and then submit it.
What I want to do now is to repeat the process, but I'm stuck when the page is reloaded. And I don't know how can I do to make the script react to the finish of the request.
The workflow I want to achieve is the following (is for automatically copying a certain object):
Popup side
Enter the number of the Master object to copy
Enter the base name of the copies (example Mod, so the I can iterate and add mod1, mod2, modn)
Enter the number of copies
Background side
Select master
Select standard options
Fill in inputs
Submit form
Wait for the page to complete the request and continue to the next copy. (here I need help)
The problem is on the repetition, the rest is taking care of. I assume that must be a way of dealing with requests. Any ideas?
By the way I'm doing it all with the extension and tabs methods of Google Chrome plus JavaScript and jQuery.
Ok, i´m going to answer the question myself based on Matthew Getner´s comment. The chrome.webRequest.onCompleted was the solution to the problem. With this method I was able to wait for the request to be completed and start over with the process. And with the messegaes methods I´ve achieved the comunication between the background and the extension itself. So I finally was able to filled a form, send it, and repeat. This way I´ve made a kind of robot to help a co-worker with a lame repetitive task on a aged web plataform.

Editing a closed case

I have a ribbon button on the case entity that updates a single two-option field on the form via javascript. When this is used on a case that has been resolved/closed it returns an error as the form is now read only.
Is there a way in javascript that I could get it to re-activate the form, change the field and then put it back to the way it was before? I have tried to force the change on the form but even if i manage to make it appear that you can save it, it will return the error as the form record is still counted as de-activated, even though you can change the fields
Thanks
You should be able to use a SOAP call for this, its a little involved, I would suggest starting here. You have to generate XML that represents the request, the link provides some tools to do this.
I believe you will need to issue JavaScript versions of SetStateRequest (to open) and CloseIncidentRequest (to close).
On the other hand, which is a different approach entirely, is to disable the button when the record is deactivated, then users have to manually renable the record make the change and close again. This is closer to 'working with the system' which I have touched upon here, its a different situation but the principle still applies.

Resources