[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

retrieving field values from one form to another

Hi all,

For my web application, I have form1 and form2. I have a bunch of fields in both the forms. Is it possible for me to display the field values of form1 in form2
For example: if i have a field "company1" in form1 and the user enters its vaLue in the browser and it gets saved.
Now, is there any way i can automatically display the value of field "company1" in the field "company2"(of the form2) ,when the form2 is opened in the browser?

Any responces greatly apprecited.

thanks
J  
0
jaggernat
Asked:
jaggernat
  • 7
  • 3
1 Solution
 
ZvonkoSystems architectCommented:
There is a pure JavaScript version for that problem using Cookies.
And a second variant using @Formulas and ProfileDocuments.

I would recommand the Cookie method. Are you interested?

0
 
jaggernatAuthor Commented:
yes , please ..i would appreciate it..

Thanks,
Jay
0
 
ZvonkoSystems architectCommented:
Ok, here a tested version:

Put this in Form1 JSHeader:

var fieldMap = ["Company1:company", "EmailAddress1:email","City1:city"];

function putFields(theForm){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
   } else {
     cVal = "";
   }
   for(i=0;i<fieldMap.length;i++){
      fVal = theForm[fieldMap[i].split(":")[0]].value;
      cNam = fieldMap[i].split(":")[1];
      cVal = cVal.replace(new RegExp(cNam+"\\=[\\w\\% \\@]*\\:","g"),"");
      cVal += cNam+"="+escape(fVal)+":";
   }
   document.cookie="sF="+cVal+";path=/;";
}

Put this in Form1 onSubmit event:

 putFields(this)


Put this in Form2 JSHeader:

var fieldMap = ["Company2:company", "EmailAddress2:email","City2:city"];

function getFields(){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
     for(i=0;i<fieldMap.length;i++){
        fNam = fieldMap[i].split(":")[0];
        cNam = fieldMap[i].split(":")[1];
         if(cPart=cVal.match(new RegExp("\\b"+cNam+"\\=([\\w\\% \\@]*)\\:"))){
            if(cPart.length==2) theForm[fNam].value = unescape(cPart[1]);
         }
      }
   }
}


Put this in Form2 onLoad event:

getFields()


Short description:
In Form1 does the Array  fieldMap contain pairs of Form1 field names (be aware of exact uppercase and lowercase characters) folowed by a colon and the name for that field in the cookie.
The name in the cookie is the field reference for any other form to get that field value not by the Field name like used in Form1 but by a normalized cookie field name.
So is the Array in Form2 also pairs with the Field names as used on Form2 and the coresponding cookie name.
You have not to use all Form1 fields in Form2. Only used field names will overwrite the Form2 fields and only if the cookie contains a value for that field.

Tell me how it works for you.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZvonkoSystems architectCommented:
Sorry, take better this function versions:


function putFields(theForm){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
   } else {
     cVal = "";
   }
   for(i=0;i<fieldMap.length;i++){
      fVal = theForm[fieldMap[i].split(":")[0]].value;
      cNam = fieldMap[i].split(":")[1];
      cVal = cVal.replace(new RegExp(cNam+"\\=[\\w\\% \\@]*\\|","g"),"");
      cVal += cNam+"="+escape(fVal)+"|";
   }
   document.cookie="sF="+escape(cVal)+";path=/;";
}


And for Form2 this:
function getFields(){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
     for(i=0;i<fieldMap.length;i++){
        fNam = fieldMap[i].split(":")[0];
        cNam = fieldMap[i].split(":")[1];
         if(cPart=cVal.match(new RegExp("\\b"+cNam+"\\=([\\w\\% \\@]*)\\|"))){
            if(cPart.length==2) theForm[fNam].value = unescape(cPart[1]);
         }
      }
   }
}


0
 
ZvonkoSystems architectCommented:
Sorry, one more improvement:

function putFields(theForm){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
   } else {
     cVal = "";
   }
   for(i=0;i<fieldMap.length;i++){
      fVal = theForm[fieldMap[i].split(":")[0]].value;
      cNam = fieldMap[i].split(":")[1];
      cVal = cVal.replace(new RegExp(cNam+"\\=[^\\|]*\\|","g"),"");
      cVal += cNam+"="+escape(fVal)+"|";
   }
   document.cookie="sF="+escape(cVal)+";path=/;";
}


And for Form2:
function getFields(){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
     for(i=0;i<fieldMap.length;i++){
        fNam = fieldMap[i].split(":")[0];
        cNam = fieldMap[i].split(":")[1];
         if(cPart=cVal.match(new RegExp("\\b"+cNam+"\\=([^\\|]*)\\|"))){
            if(cPart.length==2) theForm[fNam].value = unescape(cPart[1]);
         }
      }
   }
}



0
 
jaggernatAuthor Commented:
hi,

sorry, the problem is  a one level more complex. i want to retrieve a field value from a stored document to a form in a browser.
For a clear description, here it is:
The value of "company" field (IIT) in this link    :   http://216.47.158.148/AMSStaff.nsf/ad2205b8b2c4ae4e86256e9b000e0553/142f6f40f11c2aa486256ef500605901?OpenDocument&Highlight=0,iit*     

should be displyed in the jobtitle field  in this form link:    


 http://216.47.158.148/AMSStaff.nsf/ApplyJobs?OpenForm

do i have to make any modifications.


thanks,
J
0
 
ZvonkoSystems architectCommented:
Please assign for my work here the grade A and open a new question with more details.
My upper solution did exactly what you asked for in the original question.

I can help you with the new requirment and with the $$LoginUserForm
0
 
ZvonkoSystems architectCommented:
Ok, thanks for points and grading.

You can open a new question for the changed requirment but I can give you the answer also here: the changed requirment is far too simple!
To get a value from one document to next Form you need NO scripting. It is a built in feature of Notes to inherit values from a document to a new documetn.
Check in the new Form a form property with the label: "FormulaInheritValuesFromSelectedDocument"
That property is the first checkbox in the propelar hat tab in Form properties.
So the only thing you have to do is to click that checkbox in your Form ApplyJobs in the AMMSStaff.nsf
After that you have to put in your Field "Subject" in the ApplyJobs Form this formula for the DefaultValue: company
That's all.




0
 
jaggernatAuthor Commented:
i did check the "FormulaInheritValuesFromSelectedDocument" form property in apply jobs and gave the default value of field"subject"  as company.

But it does not display the company value in the apply jobs form..
i am confused..
How does the apply jobs form(which is dynamic) retrieve value from the static document.


thanks,
J

 
0
 
ZvonkoSystems architectCommented:
Please open a new question.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now