2

I am trying to retrieve the sub-task of the parent task from a list. query:

../_api/web/lists/getbytitle('Tasks')/items?$select=Title,Status,ParentID/Id&$expand=ParentID

Code:

function onQuerySucceeded(data) {
    var mainTasks = [];
    var subTasks = [];
    for (var i = 0; i < data.length; i++) {
        if (data[i].ParentID.Id) {
            subTasks.push(data[i]);
        } else {
            mainTasks.push(data[i]);
        }

    }
    $.each(data.d.results, function (key, value) {
        subTasks += '<strong>Title: </strong> ' + value.Title +
            ' <strong>Status:</strong> ' + value.Status + ' <strong>Parent Id:</strong> ' + value.Id +
            '<br />';
    });

    $("#divSubTaskItems").html(subTasks);

};

My results are:

undefined: "Title: Test rest Call Status: In Progress Parent Id: undefined"

0

Try adding console.log(value); inside your $.each to see what data you have:

$.each(data.d.results, function (key, value) {
    console.log(value);
    subTasks += '<strong>Title: </strong> ' + value.Title +
        ' <strong>Status:</strong> ' + value.Status + ' <strong>Parent Id:</strong> ' + value.Id +
        '<br />';
});

Most likely, value.Id is indeed undefined. This is because you don't request it

Try this REST query instead:

?$select=Title,Status,Predecessors,Predecessors/Id&$expand=Predecessors

enter image description here

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.