Check out feature triggering workflows

Forums Classic DFFS Check out feature triggering workflows

Viewing 5 reply threads
  • Author
    Posts
    • #26474
      Leon
      Participant

      Hi Alex,

      I have a list I am trying to use the check out feature for and came across an issue. When the item is being checked out it is triggering workflows and causing save conflicts. Is there a way to disable the workflow trigger on check out? Or is there a way to delay the refresh of the item until workflows are finished?

    • #26487
      Alexander Bautz
      Keymaster

      There is unfortunately no way to prevent the WF from triggering from DFFS, but you could edit the WF and configure it to exit if the CheckedOut field is checked – effectively only triggering the WF when the item is checked in again.

      If you need to delay the load to wait for the WF you can use this trigger: https://spjsblog.com/dffs/dffs-user-manual/#Workflow_status_BETA

      Use it for example to call a custom function like this in your Custom JS:

      function customReloadPage(){
          spjs.dffs.alert({
              "title": "Checking workflow status",
              "msg":"<div style='font-size:16px;padding:10px;'>The workflow hasn't finished yet. Hit OK to pause for 10 seconds and do a new check.</div>",
              "ok":function(){
                  spjs.dffs.alert({
                      "title": "Checking workflow status",
                      "msg":"<div id='customReloadMsg' style='font-size:16px;padding:10px;'></div>",
                      "noBtn":true
                  });
                  runTicker();
              },
              "cancel": function(){
                  location.href = location.href.split(/editform.aspx/i).join("DispForm.aspx");
              }
          });
      }
      
      function runTicker(){
          var ticker = 10;
          setInterval(function(){
              jQuery("#customReloadMsg").html("Doing a new check in "+ticker+" seconds...");
              ticker -= 1;
          },1000);
          setTimeout(function(){
              location.href = location.href; // looks strange, but reloads the form cleanly
          },10000);
      }

      Alexander

    • #26495
      Leon
      Participant

      Thanks I’ll give this a shot!

    • #32746
      MikeS
      Participant

      Alexander,

      I have a requirement to start a SPD WF based on changes in an OOTB multi-value lookup field. The WF would then manipulate other fields in that list (no email requirement). Is it possible for DFFS to compare a field pre-and post-edit (seems possible with some rules or Custom JS) and then trigger a SPD WF to run?

      Thanks
      MikeS

      • #32752
        Alexander Bautz
        Keymaster

        I wrote about this some years ago. See if you can get this to work from a button: https://spjsblog.com/2016/03/03/dffs-start-sp2013-workflow-from-a-button-in-a-list-item/

        If you do, you can compare current value and last saved value like this:

        var currValue = getFieldValue("TheFieldName");
        var lastSavedValue = spjs.dffs.beforeProperties.TheFieldName;
        if(currValue !== lastSavedValue){
           // Has changed
        }

        Please note that the code to trigger the workflow is async so you cannot just run it in PreSaveAction – the form will save and close before it has finished.

        Alexander

    • #32756
      MikeS
      Participant

      I did review that 2016 post during my research on your site. However, I was hoping there might be a way for DFFS to compare the last saved and current field values and then launch the SPD WF without user interaction when the form was saved – if the last saved and current values differ.

      Alternatively, it appears that the combination of your 2016 article with the script:

      var currValue = getFieldValue("TheFieldName");
      var lastSavedValue = spjs.dffs.beforeProperties.TheFieldName;
      if(currValue !== lastSavedValue){
         // Has changed
      }

      would trigger the WF upon pressing the button ONLY if the field has been changed. How would I combine this short script with the larger 2016 script – at the start?

      Thanks
      MikeS

      • This reply was modified 3 years, 2 months ago by MikeS.
      • This reply was modified 3 years, 2 months ago by MikeS.
      • This reply was modified 3 years, 2 months ago by MikeS.
    • #32761
      Alexander Bautz
      Keymaster

      You just call the function like show at the bottom of the 2016 article – getting the “onclick” attribute like this:

      spjs.workflow.initListItemWF('ab064e56-926c-477b-910e-0d3759f5b956');

      You could try adding the code I send to the dffs_PreSaveAction function like this:

      var wfTriggered = false;
      function dffs_PreSaveAction(){
          var currValue = getFieldValue("TheFieldName");
          var lastSavedValue = spjs.dffs.beforeProperties.TheFieldName;
          if(currValue !== lastSavedValue && !wfTriggered){
              // Has changed and the WF has not been triggered
              wfTriggered = true;
              spjs.workflow.initListItemWF('ab064e56-926c-477b-910e-0d3759f5b956');
              return false; // Stop the save and wait until the wf has been triggered
          }else{
              return true; // Saving the item
          }
      }

      Now you must add a callback to the 2016 wf function here (in the middle of the function):

      ...
      ...
      spjs.workflow.closeDlg();						SP.UI.Notify.addNotification(spjs.workflow.text.successMessage,false);
      // New line to trigger save of the list item
      spjs.dffs.triggerSave();
      ...
      ...

      I have not tested this so it might still need some tweaking.

      Alexander

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