Redirect after save/cancel

Forums Modern DFFS Redirect after save/cancel

Viewing 11 reply threads
  • Author
    Posts
    • #36443
      Joe Penland
      Participant

      Is there a way in Modern DFFS to redirect users to a specified page after saving or cancelling a form?

    • #36444
      Alexander Bautz
      Keymaster

      To redirect after save you must set up a rule triggering on “After save of the form” and add an action “Call a function”. Add the name “redirectToCustomUrl” in the “Function name” field and then add this function to your custom js:

      function redirectToCustomUrl(){
        location.href = "https://spjsworks.com";
      }
      

      I haven’t currently added a method to detect cancel button click (or X in the top right corner), but will look at adding a trigger to detect that also.

      Alexander

    • #36445
      Joe Penland
      Participant

      Thank you. Yes, in this instance I am sending users to the form from another page, so I want them to come back whether they save or cancel in the form. This would also apply if I just show them the display form for an item and they close it. I would like to send them back to the page of my choice. Adding a way to detect cancelling would be very helpful in order to handle both cases (save and cancel or close).

      • #36446
        Alexander Bautz
        Keymaster

        I’ll add support for detecting that in the next version.

        Alexander

      • #36447
        Joe Penland
        Participant

        Thank you! I really appreciate it.

      • #36452
        Alexander Bautz
        Keymaster

        I have published a new version with support for detecting “cancel” in a form – you find the change log over at spjsworks.com.

        Let me know how it works out.

        Alexander

    • #36515
      Joe Penland
      Participant

      I am finally getting back around to try this out and am having a bit of trouble trying to figure out how to trigger a function on cancelling a form. I don’t see a cancel event in the triggers for the rules. How do I attach my function to a cancel event?

      I appreciate your help.

    • #36517
      Joe Penland
      Participant

      Thanks for your reply. I did see those examples, but I haven’t successfully gotten my functions to trigger when the form is closed or cancelled. I am not seeing the cancel event as something I can use as a trigger.

    • #36519
      Alexander Bautz
      Keymaster

      That is correct, the trigger is the function itself – if it exists in your custom js it will be triggered when you cancel the form.

      Just drop this in your forms custom js:

      function dffs_PostCancelAction() {
        // Do something if the item is cancelled - for example redirect to another page
        location.href = "https://contoso.com/CancelMsg";
      }
      

      What is it you want to do when a form is cancelled?

      Alexander

      • #36520
        Joe Penland
        Participant

        For some reason it doesn’t seem to be working for me. We are still running v1.0.12.0, but I believe that version includes support for detecting the cancel event.

        I have this in the Custom JS of the New form:

        function saveCancelRedirect() {
        let searchParams = new URL(document.location).searchParams;
        let dffsSource = decodeURIComponent(searchParams.get(“DFFSSource”));
        console.log(‘dffsSource:’);
        console.log(dffsSource);
        console.log(typeof dffsSource);

        if (dffsSource !== undefined && dffsSource !== null && dffsSource !== ‘null’) {
        console.log(‘Redirect to ‘ + dffsSource);
        }
        }

        function dffs_PostSaveAction() {
        saveCancelRedirect();
        }

        function dffs_PostCancelAction() {
        saveCancelRedirect();
        }

        I am able to trigger the function by clicking a button, but it is not triggering when I cancel or close the form.

      • #36521
        Joe Penland
        Participant

        I also tried with this but still, I can see the action take place on clicking a button, but not on cancelling the form.

        function saveCancelRedirect() {
        let searchParams = new URL(document.location).searchParams;
        let dffsSource = decodeURIComponent(searchParams.get(“DFFSSource”));
        console.log(‘dffsSource:’);
        console.log(dffsSource);
        console.log(typeof dffsSource);

        if (dffsSource !== undefined && dffsSource !== null && dffsSource !== ‘null’) {
        location.href = dffsSource;
        }
        }

      • #36522
        Joe Penland
        Participant

        I realized I didn’t really explain my purpose. I want to set up the function so it can dynamically pull the redirect destination from the URL search parameters because the page I link FROM may change and I am putting the current page in the search parameters under a “DFFSSource” parameter. If that parameter is present, I want to redirect users to whatever URL is passed. I am testing with “https%3A%2F%2Fwww%2Egoogle%2Ecom” as the source and it logs correctly in the console as https://www.google.com just before navigating to Google when I test by clicking a button. When I cancel the form, nothing logs to the console and nothing happens. I don’t get errors, I just don’t get anything.

    • #36523
      Alexander Bautz
      Keymaster

      You are right, this doesn’t work… I had a typo in the code and it only works if you use it in a “child form” (view / edit of a vLookup or when opening a lookup item).

      I’ll get this fixed in the next version later this week.

      Sorry for the inconvenience!

      Alexander

      • #36524
        Joe Penland
        Participant

        No problem! Thank you for all you do to make this a great product that works for so many different scenarios. I look forward to testing it out again after the next version comes out.

    • #36528
      Alexander Bautz
      Keymaster

      I have published a new version – please let me know how it works out.

      Alexander

    • #36535
      Joe Penland
      Participant

      It looks like everything is working now! Thank you for publishing the new version with the update.

    • #37023
      Sarah O
      Participant

      Hi Alexander,

      I’d like to redirect the user to our homepage instead of the default list when a form is saved or cancelled. I tested the following codes in the custom JS tab on all forms and I am still being redirected to a list instead of the intended URL. (used google URL for confidentiality purposes). Can you please take a look at the codes I’m using for any errors?

      function dffs_PostCancelAction() {
      location.href = “https://google.com”;
      }

      function dffs_PostSaveAction() {
      location.href = “https://google.com”;
      }

      Currently operating on the following versioning of DFFS:
      Dynamic Forms for SharePoint v4.4.5.27 – July 30, 2023
      CSS version: 4.51 / 4,51
      spjs-utility version: 1.356
      Loader version: v2

      • #37024
        Sarah O
        Participant

        UPDATE TO CODES:

        For some reason when I posted this reply the code was corrupted. I attached a screenshot to this post

        Attachments:
    • #37026
      Alexander Bautz
      Keymaster

      Hi Sarah,
      The method you refer to is for the Modern DFFS version. I see from the version details that you use the classic DFFS and you must use code like this:

      function dffs_PreSaveAction(){
        spjs.dffs.redirect("https://The_address_to_redirect_to_after_save",false);
      }
      

      Alexander

    • #37032
      Sarah O
      Participant

      Thank you, I tried this and it worked for redirecting on save.

      Is there a similar functionality to redirect on cancel? I tried PreCancelAction, PreCloseAction, with the same syntax and neither worked

      • #37034
        Alexander Bautz
        Keymaster

        Hi,
        There is no built in method, but you can attach a click function to the cancel button by adding this to your custom js:

        jQuery("input[id$='diidIOGoBack']").click(function(){
            location.href = "https://spjsblog.com/DFFS";
        });
        

        Alexander

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