Change Task Status field based on Predecessor Tasks

Home Forums Classic DFFS Change Task Status field based on Predecessor Tasks

Tagged: , ,

Viewing 7 reply threads
  • Author
    Posts
    • #17251
      mk3jamie
      Participant

        Having some trouble creating a rule that will set the Task Status field in one tab to read only or hidden, unless all Subtasks in the predecessor tab are marked as complete.

        The aim is to stop users from editing a task and marking it as complete when it still has Subtasks attached to it that are still to be marked as complete. At this point i’m thinking that using the custom JS option might be the better route but not sure how I would ideally go about implementing that.

        Any help or suggestions are much appreciated.

        • This topic was modified 7 years, 5 months ago by mk3jamie.
      • #17261
        Alexander Bautz
        Keymaster

          Hi,
          How are the subtasks connected – is it trough a multi lookup column where you select other tasks, or do you use the vLookup plugin in DFFS?

          If you use a lookup column, you can add a calculated column to the task list like this:

          =Title&" ("&Status&")"

          Then add this code to the custom js in your form – change the field name “Subtasks” to match your field name:

          function checkSubTaskStatus(){
              var arr = getFieldValue("Subtasks"), pass = true;
              jQuery.each(arr,function(i,v){
                  if(v.match("(Closed)") === null){
                      pass = false;
                      return false;
                  }
              });
              return pass;
          }

          Then set a rule with trigger “custom JavaScript function” and add the name of the above function.

          Alexander

        • #17263
          mk3jamie
          Participant

            Thanks for the quick reply Alex.

            I am indeed using a Lookup column to connect the subtasks (predecessor tasks) with a project task. I’ve created the calculated column, added in the custom JS and set up the rule to trigger it but i’m currently getting a “function is undefined “” ” error message when I try to trigger it.

            Most likely i’m missing something completely obvious but can’t seem to remedy it just yet!

            Thanks again for your help.

          • #17271
            Alexander Bautz
            Keymaster

              For the code snippet to work, the “display field” in the lookup must be changed to the new calculated column – so it shows “Task (status)”.

              If you are using the latest version there is a timing issue where the custom js loads a few milliseconds to late – causing rules that trigger on load to fail. I’m working on a solution – and have posted a new version of the frontend js file here. I haven’t been able to verify that it works properly so there might be some issues left related to loading custom js files, but the custom js texarea code should work.

              Can you test it and see if it helps?

              Alexander

            • #17275
              mk3jamie
              Participant

                Tested it and still the same error message sadly, “function “” is undefined”. Anything else I can try Alex? Really dislike bugging you with these silly questions but i really do appreciate your help!

                Regards,
                Jamie.

              • #17277
                mk3jamie
                Participant

                  Did a fresh install of DFFS and now the rule and the function both load in perfectly 🙂
                  However the rule itself is not turning the task status field into a read-only field if there are still incomplete tasks. How do i go about setting up the rule to achieve this?

                  Currently it’s set to kick in on form load and field change, and will set the Task Status field to “read only”

                • #17296
                  Alexander Bautz
                  Keymaster

                    Sorry, my bad – I just tested this now, and it’s actually a bug in the script that makes this rule not trigger properly. I’ll fix it in the next release, but in the meantime you can change the rule you have to trigger on “The form is ready” – adding the function name to the “Run these functions / trigger these rules” field.

                    Change the Custom JS function like this – and change the field name in yellow:

                    function checkSubTaskStatus(){
                        var arr = getFieldValue("Predecessors"), pass = true;
                        window.alert(arr);
                        jQuery.each(arr,function(i,v){
                            if(v.match("Completed") === null){
                                pass = false;
                                return false;
                            }
                        });
                        if(!pass){
                            spjs.dffs.doReadOnly(["StatusColumnName"]);
                        }
                    }

                    Alexander

                  • #17301
                    mk3jamie
                    Participant

                      Spot on Alex, works like a dream. Thank you for the help!

                      Jamie.

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