Infopath2007 opens a second form and copies certain data from first - InfoPath Dev
in

InfoPath Dev

Infopath2007 opens a second form and copies certain data from first

Last post 03-24-2009 07:43 AM by PhilNy. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 02-20-2009 07:31 AM

    Infopath2007 opens a second form and copies certain data from first

     Hi,

    I have Infopath 2007 form called Form1 linked to a access database. When a certain list box is selected to YES then this triggers Form2 to open.

    How can I copy CERTAIN fields from Form1 to Form2 that was just entered? Using Visual Basic?

    Or is it easier to do this another way? 

  • 02-20-2009 08:35 PM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    maybe I should ask the question differently? I have gotten no replies.

    Assistance appreciated, thanks

  • 02-26-2009 12:02 PM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    With the help of Jimmy from this Forum, I was able to Copy the selected data & add it to the clipboard in Visual Basic.

    However, when infopath2 is automatically opened, I want to PASTE the data -on clipboard- to very first null field.

    Its been a long week and I have no working solution. I even tried using

    SendKeys.Send("^v")

    But thats just gives me a bunch of security errors. Search engines comes back with no answers. Any assistance would be appreciated.

  • 02-27-2009 09:14 AM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    Hi Wil

    I'm not certain you can open a new form, then copy data from old form to new form programmatically as the new form would have a different working storage area on your hard disk.

    Regardless, I'll explain a similar situation I do for my users.  They wanted to copy a form, data and all, to a new form with the click of a button. 

    What happens is they click a button, the background script saves the form they have open and keeps it open.  The script also modifies a date field that is used in the creation of new forms so when they save again, a new form is created instead of overlaying the original form they opened.  The script also runs through the digital signatures and forces the user to delete them before they can continue.

    You could use this method to clear out fields you didn't need (similar to the way I run through the digital signatures) and the user would have a new form with only the fields they need copied.

    Let me know if you want more info on how this is done.

    Petro

    :o)
  • 02-27-2009 09:23 AM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    Thanks for the info.

    I was able to copy to clipboard and open new form. I can paste the 1 field manually but was looking for an automated way.

    But if you can reply with the code for your sugestion it would be appreciated. By the way its only for 1 field. Thanks!

  • 02-27-2009 09:33 AM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    Certainly.  It's in JScript tho - sorry :(

    function deletesignature::OnClick(eventObj)

    {

     var vContinue;

     vContinue = XDocument.UI.Confirm("This original form will be saved and closed.\r" + "In the copied form, status will be reset and digital signatures will be deleted .\r" + "Do you wish to continue?",4);

     if (vContinue == 6) // if the user clicked "YES". { CopyForm(); }

     }

    function CopyForm() {

    var vNewDate = new Date();

    var xDateTime = XDocument.DOM.selectSingleNode("/my:ChangeForm/my:General_Information/my:DateTime");

    var xStatus = XDocument.DOM.selectSingleNode("/my:ChangeForm/my:General_Information/my:Status");

    var vCt1 = XDocument.SignedDataBlocks.Count

    var xSDBs = XDocument.SignedDataBlocks;

    var rc = 0;

    imo = vNewDate.getMonth() + 1;

    id = vNewDate.getDate();

    iy = vNewDate.getFullYear();

    ih = vNewDate.getHours();

    imin = vNewDate.getMinutes();

    isec = vNewDate.getSeconds();

    if (id < 10) id = '0' + id;

    if (imo < 10) imo = '0' + imo;

    if (ih < 10) ih = '0' + ih;

    if (imin < 10) imin = '0' + imin;

    if (isec < 10) isec = '0' + isec;

    vdt = iy + "-" + imo + "-" + id + "T" + ih + "_" + imin + "_" + isec;

    rc = SubmitForm();

    // submit the old form.

    if ((rc == 200) || (rc == 201)) { 

    XDocument.UI.Alert("The original form was saved! You are now working on a copy.\r If you get the Digital Signature popup, please 'Remove' all signatures."); }

    else {

    XDocument.UI.Alert("There were problems submitting your form. Error Code " + rc);

    return; } 

     xDateTime.text = vdt;

     xStatus.text = "Planning";

    // if there are any Digital Signatures, loop until they are removed.

    do {

    var j = 0; for(var i=0;i<=(vCt1 - 1);i++)

     { j = j + xSDBs(i).Signatures.Count; }

     if (j > 0) XDocument.UI.ShowSignatureDialog();

    }

     while (j > 0);

     }

    Hope you find it helpful.

    :o)
  • 03-16-2009 07:06 AM In reply to

    • PhilNy
    • Not Ranked
    • Joined on 03-13-2009
    • Posts 4

    Re: Infopath2007 opens a second form and copies certain data from first

    This issue is close to a problem that I'm having. I have an IP 2007 form built on an MS SQL 2005 DB. I'm able to create, update & delete records just fine. But - I'd like to be able to query for an existing record, edit it (including removing primary key data  - as the PK uses IDENTITY to create new keys) and then submit to create a new record. I don't want to use a New Record button as it clears all the fields and makes our data entry people have to type in every field value again. I wrote a simple JScript to clear the key fields (actually, the form works with four tables - the root and then three others linked PK-FK) but I'd then like to save the rest of the fields, then effectively create a New Record and then paste the old field values into the new record. They then could be edited & then submitted as a brand new record. This seems like something that a lot of poeple would be doing but so far I've not seen these operations described in any blogs or discussion lists. Many Thanks in advance. Phil

  • 03-19-2009 06:56 PM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    Hi Phil - I'm on vacation now but will reply when I return to work on the 23rd.

    Dave

    :o)
  • 03-23-2009 08:53 AM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    Phil - the form I used to do this does not use any primary keys or databases, just information stored in SharePoint Lists.

    The copy function is a button in all existing forms.  This is the process when you press it.

    1. Pushing the copy button saves the existing form.
    2. It then will continuously prompt you to remove all digital signatures until they are all gone.
    3. It then resets a date-time field that was used to create the original form (the one that was saved in step 1) to the current date and time. 
      This is needed for my forms as the other field used to create the form name could be duplicated - which would cause an overlay situation if not reset.
    4. All other fields remain untouched, but when you then save this form, it creates a new form for you.

    You could obviously modify the script to keep or erase whatever fields you want when you push the "Copy Form" button.

    Hope this helps.

    Dave

    :o)
  • 03-23-2009 12:57 PM In reply to

    • PhilNy
    • Not Ranked
    • Joined on 03-13-2009
    • Posts 4

    Re: Infopath2007 opens a second form and copies certain data from first

    That sounds great, but is there a script for this that is then attached to a custom button? I don't see a Copy button by default anywhere in my forms - only Submit on the toolbar. Looking at the available built-in button actions I don't see Copy among them there, either. I am able to clear & reset values in a form but just don't see the Copy action. Thanks! Phil

     

  • 03-23-2009 01:16 PM In reply to

    Re: Infopath2007 opens a second form and copies certain data from first

    Sorry  - yes, you would have to write the script to perform the actions I described above.

    Below is the code associated with the Copy Button (with the id of deletesignature)

    function deletesignature::OnClick(eventObj) {

    var vContinue;

    vContinue = XDocument.UI.Confirm("This original form will be saved and closed.\r" + "In the copied form, status will be reset and digital signatures will be deleted .\r" + "Do you wish to continue?",4);

    if (vContinue == 6) // if the user clicked "YES". {

    CopyForm();

     }

     }

    function CopyForm() {

    var vNewDate = new Date();

    var xDateTime = XDocument.DOM.selectSingleNode("/my:ChangeForm/my:General_Information/my:DateTime");

    var xStatus = XDocument.DOM.selectSingleNode("/my:ChangeForm/my:General_Information/my:Status");

    var vCt1 = XDocument.SignedDataBlocks.Count

    var xSDBs = XDocument.SignedDataBlocks;

    var rc = 0;

    imo = vNewDate.getMonth() + 1;

    id = vNewDate.getDate();

    iy = vNewDate.getFullYear();

    ih = vNewDate.getHours();

    imin = vNewDate.getMinutes();

    isec = vNewDate.getSeconds();

    if (id < 10) id = '0' + id;

    if (imo < 10) imo = '0' + imo;

    if (ih < 10) ih = '0' + ih;

    if (imin < 10) imin = '0' + imin;

    if (isec < 10) isec = '0' + isec;

    vdt = iy + "-" + imo + "-" + id + "T" + ih + "_" + imin + "_" + isec;

    rc = SubmitForm();

    // submit the old form.

    if ((rc == 200) || (rc == 201)) {

    XDocument.UI.Alert("The original form was saved! You are now working on a copy.\r If you get the Digital Signature popup, please 'Remove' all signatures."); }

    else { // eventObj.ReturnStatus = false;

    XDocument.UI.Alert("There were problems submitting your form. Error Code " + rc); return; } 

    xDateTime.text = vdt; // Phil - this is one of the fields used in the name of the form.  It gets set to the current date/time to create a new record, even if the user leaves the "Title" field the same.

    xStatus.text = "Planning"; // Phil - this field is being set to its initial value.

     // Clear out any 'submitted' IAF tasks and task numbers from the Web Application view.

    var xSubmitted = XDocument.DOM.selectNodes("/my:ChangeForm/my:Web_App_Group/my:JVM_R_Section/my:JVM_Key/my:Submitted");

    var xTask_Number = XDocument.DOM.selectNodes("/my:ChangeForm/my:Web_App_Group/my:JVM_R_Section/my:JVM_Key/my:Task_Number");

    for(var i=0;i<=(xSubmitted.length - 1); i++) {

    xSubmitted.item(i).text = "";

    xTask_Number.item(i).text = ""; }

    // if there are any Digital Signatures, loop until they are removed.

    do { var j = 0; for(var i=0;i<=(vCt1 - 1);i++) {

    j = j + xSDBs(i).Signatures.Count; }

    if (j > 0) XDocument.UI.ShowSignatureDialog(); }

    while (j > 0); }

     // end of code

     Obviously this may not all fit with your application and you'll need to make some coding changes.  This code above resets a status, and some fields that once entered, are protected.  Otherwise it leaves everything else in tact, and the user has a complete copy of a previous form - this is very beneficial if the user entered a large amount of data and does not want to enter it in again on a new form.

    Dave

    :o)
  • 03-24-2009 07:43 AM In reply to

    • PhilNy
    • Not Ranked
    • Joined on 03-13-2009
    • Posts 4

    Re: Infopath2007 opens a second form and copies certain data from first

    This looks great. This is the first coding that I've done with IP07 so I'll have to fool around a bit but the options you have - esp. removing signatures are super. I think this will interest a lot of people. Many Thanks! Phil

Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.