Looking for a Way to use onclick function to Archive Form Entries

Forums Dynamic Forms for SharePoint Looking for a Way to use onclick function to Archive Form Entries

Viewing 4 reply threads
  • Author
    Posts
    • #33141
      Jeverly
      Participant

      I am looking for a way to be able to archive and unarchive form entries using onclick function at the top of the edit form. Ideally the business would like to open a form entry and click a button or choice field y/n (labeled archive) to trigger a popup box that allows the user to add archive details. Once the details are added then the user would click save/or submit and that would trigger an action that would remove the form from the default view in the library. Ideally they would like to be able to unarchive the form the same way and have it go back into the default view library. Is this possible within DFFS?

    • #33145
      Alexander Bautz
      Keymaster

      Hi,
      Yes, this is possible. Add this to your Custom JS:

      function flagAsArchived(){
          spjs.modal.add({
              "title": "Archive this item",
              "html": "<div style='font-size:1.2em;'>Archive details</div><textarea id='archiveDetailsTextarea' style='width:100%;box-sizing:border-box;height:100px;'></textarea>",
              "closeOnOK": false,
              "ok": function(){
                  setFieldValue("Your_boolean_archived_field", true);
                  var msg = jQuery("#archiveDetailsTextarea").val();            
                  setFieldValue("Your_archive_details_note_field", msg);
                  spjs.dffs.triggerSave();
              },
              "cancel": function(){
                  // Close dialog
              },
              "showClose": false,
              "allowMaximize": false,
              "resizable": false
          });
      }

      Then create a button or a rule where you call this function.

      Change “Your_boolean_archived_field” and “Your_archive_details_note_field” to match your field names. Also change the filter in your default list view to not show the items flagged as “Archived”.

      Using this same approach you can create another function to un-archive the item by changing the setFieldValue of “Your_boolean_archived_field” to false.

      Alexander

    • #33149
      Jeverly
      Participant

      This has worked great! Thank you. I have the unarchive button created to reverse the archive function and have updated the field names and setfieldfalue to false. But when the Unarchive button is clicked, it does not make the entry visible again in the default view for the library. Also, is there a way to make the unarchive button visible only if the entry is currently archived? Instead of seeing both buttons on the edit form?

    • #33156
      Alexander Bautz
      Keymaster

      If you give each of the buttons an ID and hide them initially:

      <input type="button" id="archive_btn" style="display:none;" value="Archive" onclick="the_archive_function()">
      <input type="button" id="undo_archive_btn" style="display:none;" value="Undo archive" onclick="the_undo_archive_function()">

      You can now set up two rules – one for “Archived = yes” and one for “Archived = no” – have them run ON FORM LOAD only and add the ID of the button you want to show in the “Visible headings or elements” textarea. This will now show the correct button based on the archived field being checked or unchecked.

      Regarding the visibility in list view: you must ensure that the code actually sets the “Archived” field to false when you run the function and that the view is actually filtered on that field.

      Alexander

    • #33205
      Jeverly
      Participant

      Hello,

      There is still one piece of this setup that I can’t get right. How do I get the details the user adds to the popup box copied over to an actual form field? Or is it possible to have the popup box be an actual form field itself? That would eliminate the need to have the contents entered into the popup box copied over to a form field. Thanks again for all of your help on this.

      • #33219
        Alexander Bautz
        Keymaster

        This is happening in these lines in the original code:

        // Getting the value from the textarea
        var msg = jQuery("#archiveDetailsTextarea").val();
        // Writing the value to the form - you must replace "Your_archive_details_note_field" with the internal name of your field.
        setFieldValue("Your_archive_details_note_field", msg);

        Alexander

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