1

I have a task list from a Sharepoint Online site that is synced with MS-Project.

I created a top level task item that everything else is nested under. However the ID of that task is very large because I added it late. I want to pull information from this item, however the only way I can figure out how to reference it is by Name (which is not guaranteed unique).

Is there a way to reference the first item in a list (or list view)?

Basically I am expecting to be able to reference it like this

currentItem:ID equals 1

where ID is some id.

GUID, ID, TaskOrderId, Order, etc does not seem to work.

Here is an example: enter image description here

Notice how "Task 1" which is the first task and the one I want to get, has an ID of "98". I am looking for some way to reference the first or "top" task other than by name. Clearly Sharepoint knows that the task should come first even though it was added after all the other tasks. What is the column that gives me the position (index) into the task list?

  • Is this happening within an SPD workflow ? – Charles Mar 3 '16 at 20:23
  • @Charles, Yes - I am using Sharepoint Designer – ChronoFish Mar 3 '16 at 20:26
  • And what do you exactly want to do ? ID equals 1 works fine, but as you write currentItem:ID, it feels like you are trying to do something different. For example, if you want to update a field in this item, you call an Update Item action, put fields to be updated and as the condition set ID equal to 1 – Charles Mar 3 '16 at 20:40
  • @Charles : I have updated the question to include an example. I hope this helps clarify what I am trying to reference. – ChronoFish Mar 3 '16 at 21:12
  • One last question, sorry it must be me being tired. Do you know the ID "98" and want to make a change on Task 1 using that ID ? Or do you want to find a way to return you the ID of the task on the top ? i.e. way to programatically find the value of the top ID which is in this case 98 ? – Charles Mar 3 '16 at 21:58
3
+50

Use CSOM / JSOM with CAML to get all tasks where ParentID is NULL, i.e. all top level tasks.

// Create Context etc first
List list = context.Web.Lists.GetByTitle(listTitle);
CamlQuery query = new CamlQuery();
query.ViewXml =
    @"<View>
        <Query>
            <Where>
                <IsNull><FieldRef Name='ParentID' /></IsNull>
            </Where>
        </Query>
    </View>";
ListItemCollection items = list.GetItems(query);

If you want a specific task, i.e. in your case the fist shown, this is view dependent. Check what the definition for the view is i.e. the ordering. Then order the resulting collection of the query above (or add the OrderBy clause to your CAML query) and take the first item.

  • Do yo know what the default ordering is for the "Gantt" view? – ChronoFish Mar 11 '16 at 16:35
  • @ChronoFish I will try to do a test case on this tomorrow if I have time – Colin Mar 11 '16 at 23:09
  • @ChronoFish,you can get the Query / Sort order for the (default) view by accessing the list.Views["<View ID or Title>"].Query property – Colin Mar 14 '16 at 19:44
0

If you want to get single largest parentID item then,

1.Set the list items in descending order.
2.Set row limit to 1.

query.ViewXml =
"<View>
<RowLimit>1</RowLimit>
    <Query>
        <Where>
            <IsNull><FieldRef Name='ParentID' /></IsNull>
        </Where>
        <OrderBy>
            <FieldRef Name="ParentID" Ascending="False" />
       </OrderBy>
    </Query>        
</View>"

Above query return single item whose ParentID is largest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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