Create Copy from DispForm or EditForm

Forums Classic DFFS Create Copy from DispForm or EditForm

Viewing 2 reply threads
  • Author
    Posts
    • #36084
      Sanchez
      Participant

      Hi Alexander, I currently have a ‘Save & Copy to New Form Entry’ button and working perfectly; however, the team also needs to create a ‘Copy to New Form Entry’ from a DispForm or EditForm. I wasn’t able to figure out how to add the button from DispForm since there is a Save

      I couldn’t even get it started from DispForm at all. I started to from EditForm but it’s trying to copy to another EditForm instead of Copying to a NewForm

      http://contoso.com/sites/xxx/xxx/Lists/xxx/EditForm.aspx?CreateCopy=1

      if I changed the address line to …..NewForm.aspx?CreateCopy=1 then it’s perfect.

      1 – What can I change below so it doesn’t require a Save to trigger the copy and start new entry?
      2 – What can I change from the following code to have the CreateCopy=1 open as NewForm instead of EditForm?
      3 – What can I change from the code below to add a button and trigger copy/start new form from Display?

      // If creating a copy
      if(GetUrlKeyValue(“CreateCopy”) === “1”){
      var str = sessionStorage.getItem(“SaveAndCreateNewData”), data;
      if(str !== null){
      data = JSON.parse(str);
      jQuery.each(data,function(fin,val){
      setFieldValue(fin,val);
      });
      }
      }
      // Add button
      jQuery(“input[id$=’_diidIOSaveItem’]”).after(“<input type=’button’ class=’ms-ButtonHeightWidth’ style=’margin-right:4px;’ value=’Copy & Start a New Entry’ onclick=’saveAndCopy()’ />”);
      var createCopyWhenSaving = false;
      function saveAndCopy(){
      createCopyWhenSaving = true;
      spjs.dffs.triggerSave();
      }
      function dffs_PreSaveAction(){
      if(createCopyWhenSaving){
      var arr = [
      “FieldInternalNameA”,
      “FieldInternalNameB”,
      “FieldInternalNameC”
      ];
      var data = {};
      jQuery.each(arr,function(i,fin){
      data[fin] = getFieldValue(fin);
      });
      sessionStorage.setItem(“SaveAndCreateNewData”,JSON.stringify(data));
      // Redirect
      spjs.dffs.redirect(location.pathname + “?CreateCopy=1”,false);
      }
      return true;
      }

    • #36085
      Alexander Bautz
      Keymaster

      From EditForm you only need to change this line:

      spjs.dffs.redirect(location.pathname + "?CreateCopy=1",false);
      

      like this:

      spjs.dffs.redirect(location.pathname.replace(/editform.aspx/i, "NewForm.aspx") + "?CreateCopy=1",false);
      

      From DispForm you must change the function like this:

      function saveAndCopy() {
        var arr = [
          "FieldInternalNameA",
          "FieldInternalNameB",
          "FieldInternalNameC"
        ];
        var data = {};
        jQuery.each(arr, function (i, fin) {
          data[fin] = getFieldValue(fin);
        });
        sessionStorage.setItem("SaveAndCreateNewData", JSON.stringify(data));
        // Redirect
        location.href = location.pathname.replace(/dispform.aspx/i, "NewForm.aspx") + "?CreateCopy=1";
      }
      

      Alexander

    • #36094
      Sanchez
      Participant

      Thank you! I can’t get the button to show up on DispForm.

      // Add button
      jQuery(“input[id=’_editItemBtn’]”).after(“<input type=’button’ class=’ms-ButtonHeightWidth’ style=’margin-right:4px;’ value=’Copy & Start a New Entry’ onclick=’saveAndCopy()’ />”);
      var createCopyWhenSaving = false;
      function saveAndCopy(){
      createCopyWhenSaving = true;
      spjs.dffs.triggerSave();
      }

      also tried changed beginning of line one to jQuery(“input[id=’dffs_editItemBtn’]”).after and also jQuery(“#dffs_editItemBtn”).after but can’t figure it out.

      • #36095
        Alexander Bautz
        Keymaster

        You were on the right track changing the ID of the button, but this button is inserted after a timeout (because of some internal calculations) so you must wrap it in a setTimeout like this:

        setTimeout(function(){
            jQuery("#dffs_editItemBtn").before("<input type='button' class='ms-ButtonHeightWidth' style='margin-right:4px;' value='Copy & Start a New Entry' onclick='saveAndCopy()' />");
        },1500);
        

        Alexander

Viewing 2 reply threads
  • You must be logged in to reply to this topic.