This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



May 15, 2012, 9:55 PM
24 Posts
topic has been resolvedResolved

Clicking button and saving document causes 2 versions of documents to be created

  • Category: Dojo and Client Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 4
Referring to this post:
http://www-10.lotus.com/ldd/xpagesforum.nsf/topicThread.xsp?action=openDocument&documentId=DD8F4B72C4CE5B45852579FE0075C084
 
I have a button on an XPage that:
1. Uses the XMLHttpRequest to call a servlet
2. Returns JSON which I parse to grab the correct name/value pair(s)
3. Populate the fields on the document on the client side
 
It now seems to create 2 versions of the document when I save the document:
Version 1 has the hidden fields that I populate on the postNewDocument event
Version 2 has the fields that I fill in on the form
 
Neither version has all the fields "together"...
 
Is there something in my button's code that would cause this to happen?
 
Button code:
var url = "http://myurl.com";     // generic url...
var returnValues;
var jsonValues;
var jsonName;
var jsonValue;
var xhr;
var doc = document.forms[0];

if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("GET", url, true);
xhr.send(null);
xhr.onreadystatechange = function (){
                if (xhr.readyState == 4) {                                                               
                    if (xhr.status == 200) {
                        returnValues = xhr.responseText;
                        jsonValues = eval('(' + returnValues + ')');
                        for (i = 0; i < jsonValues.items.length; i++) {
                            jsonName = jsonValues.items[i].name;
                            jsonValue = jsonValues.items[i].value;
                            if (jsonName == "name") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Name1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "job") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Title1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "loc") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Location1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                                //document.getElementById("view:_id1:_id2:facetMiddle:include1:tabPanel1:sr_Location1").value = jsonValue;
                            }
                            if (jsonName == "mail") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Email1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "phone") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Phone1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }

                        }

                }
            }                                                            
        };

Very confused on this one...
 
Thanks!
Dan
 
 
May 16, 2012, 7:08 AM
135 Posts
Re: Clicking button and saving document causes 2 versions of documents to be created
And if you don't click the populate button, the save works fine? How about if you add default values to the hidden fields, are those saved OK if you don't click the button?
 
If the above works fine I would simplify the button code by using dojo.xhrGet and dojo.byId and make it update only one field to start with.
 
- Panu 
May 16, 2012, 12:46 PM
24 Posts
Re: Clicking button and saving document causes 2 versions of documents to be created
Opening a new document, enter values in the fields without touching the button, and saving causes the same issue.
 
Not sure what is happening...
 
Any other ideas?
 
Thanks!
Dan
May 18, 2012, 4:21 PM
135 Posts
Re: Clicking button and saving document causes 2 versions of documents to be created
What's in the save button? I've had multiple documents when 2 of these 3 are in place: button type is "Submit", save property is true, there is a "Save Document" action in onclick event.
 
- Panu 
May 21, 2012, 8:08 PM
24 Posts
Re: Clicking button and saving document causes 2 versions of documents to be created
I never determined the issue, but just rebuilt the custom controls and it is working again...

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal