0

I'm currently using the following piece of code to hide all the subtasks from my view.

<script
      src="https://code.jquery.com/jquery-3.2.1.min.js"
      integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
      crossorigin="anonymous"></script>

<script>
jQuery(document).ready(function(){
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', run);
});

function run(){
    jQuery('div[class="ms-vb  itx"]').find('span[style]').each(function(){
        var left = Number(jQuery(this).css('margin-left').replace("px",""));
        if(left>20){
            jQuery(this).parent().parent().parent().remove();//hide();
        }
    });
}
</script>

I'm now trying to convert that list of parent tasks into a Gantt view however it still displays the subtasks inside said Gantt view and i've had no success trying to hide them.

Any help hiding the subtasks on the Gantt view is greatly appreciated.

I

2 Answers 2

3

First, your script just show Top-Level Main Tasks (Summary Task) not the Sub-Level Main Tasks.

For Example: If you have subtask (Task2 and Task 4) that is the Main Task for another child subtask (Task 3, Task 5)

- Main Task MQassas 1
 - Task 2
     - Task 3
- Main Task MQassas 2
 - Task 4
     - Task 5

It will only show the Parent Main Task (Main Task MQassas 1, Main Task MQassas 2) as shown below:

enter image description here


Second, To get the same behavior without code in Gantt chart, you should do the following:

  • Setting the Predecessor field for all Subtasks with the Main Task.

enter image description here

[OutPut]

enter image description here

  • Now, Create a new Gantt chart filtered by Predecessor equals empty enter image description here

[OutPut]

enter image description here


An alternative OOTB solution,

You can also create a new column (IsMainTask) that is (Yes or No) to only update the main tasks with yes and filter with this IsMainTask= Yes, in this case, you will update little main tasks instead subtasks!

3
  • Appreciate the response and it's a good way to do what I need it to do. However this way would result in having to set the Predecessors for each sub task manually would it not? Which is quite a laborious option as there could potentially be hundreds of tasks to update.
    – cod3r_jim
    Nov 3, 2017 at 9:24
  • @cod3r_jim Although this laborious option but this is an OOTB option no need workflow, and the best practice is to fill predecessor before! also an alternative solution, you can also create a new column that is (Yes or No) to only update the main tasks with yes and filter to show only yes, in this case, you will update little main tasks instead subtasks :) do you checked my updated answer! Nov 3, 2017 at 10:10
  • Thanks again. Sadly the client is importing massive task lists via MS Project where he does not set any predecessor tasks so i couldn't rely on the predecessor info being filled out. What formula or validation are you using to set the value in the yes/no field?
    – cod3r_jim
    Nov 4, 2017 at 11:38
1

So for anyone else who happens to randomly need this solution, this is how i'm currently doing it.

Create a simple text field in your task list as a place holder, "subTask" for example.

Then create a 2010 Workflow in Sharepoint Designer and create a IF statement.

enter image description here

Every top level task does not contain a Parent ID, so any subtask created will have their placeholder field updated as they will contain a Parent ID.

You can then filter your view based on that field.

enter image description here

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.