Home › Forums › Classic DFFS › Change Task Status field based on Predecessor Tasks
Tagged: DFFS, Javascript, rules
- This topic has 7 replies, 2 voices, and was last updated 7 years, 4 months ago by mk3jamie.
-
AuthorPosts
-
-
July 12, 2017 at 14:14 #17251
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, 4 months ago by mk3jamie.
-
July 13, 2017 at 09:10 #17261
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
-
July 13, 2017 at 10:40 #17263
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.
Attachments:
-
July 13, 2017 at 21:28 #17271
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
-
July 14, 2017 at 09:32 #17275
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. -
July 14, 2017 at 09:57 #17277
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”
-
July 16, 2017 at 11:03 #17296
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
-
July 17, 2017 at 10:33 #17301
Spot on Alex, works like a dream. Thank you for the help!
Jamie.
-
-
AuthorPosts
- You must be logged in to reply to this topic.