using JSOM i am displaying a list of a workflow task...in order to allow my users to approve the task i need to get the ID of the related item. I'm guessing this is going to be in the Related Item column as an object? Or does this ID exists somewhere in the list?


Final solution below.

function getMyTasks() {
var rptMyTasks = document.getElementById("myTaskListRow");
rptMyTasksList = web.get_lists().getByTitle('WorkflowTaskList');
//var camlQuery = SP.CamlQuery.createAllItemsQuery();
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='AssignedTo' LookupId='TRUE' /><Value Type='Integer'><UserID /></Value></Eq></Where></Query></View>");
var rptMyTasksListItems = rptMyTasksList.getItems(camlQuery);

    function () {
        // Success returned from executeQueryAsync

        if (rptMyTasksListItems.get_count() > 0) {
            var rptMyTasksListItemEnumerator1 = rptMyTasksListItems.getEnumerator();

            // Lets get the select items
            while (rptMyTasksListItemEnumerator1.moveNext()) {
                var rptMyTasksListItem1 = rptMyTasksListItemEnumerator1.get_current();
                var obj = JSON.parse(rptMyTasksListItem1.get_item("RelatedItems"));
                var RelatedItemID = obj[0].ItemId;

                rptMyTasks.innerHTML += "<tr><td>" + rptMyTasksListItem1.get_id() + "</td>" +
            "<td>" + rptMyTasksListItem1.get_item("PercentComplete") + "% " + "</td>" +
            "<td><div class='btn btn-warning btn-xs' onclick='viewGhRecordDetails(" + RelatedItemID + ");'>View " + rptMyTasksListItem1.get_item("Title") + "</div></td>" +
            "<td>" + rptMyTasksListItem1.get_item("Status") + "</td></tr>";

        else { $('#tblmyTasksNoRecords').show(); $('#tblmyTasks').hide(); }

    function (sender, args) {
        // Failure returned from executeQueryAsync
        alert("Error in XXXXXX Tasks: " + args.get_message());

  • careful with JSON.parse, not all browsers support it – MdMazzotti Jan 21 '14 at 12:09
  • SP2013 doesn't support IE7-. – iOnline247 Jan 22 '14 at 4:18

If it is indeed what the Related Item brings back, then it's just a normal json object and you can do this:

var obj = [{"ItemId":2,"WebId":"860915f4-6bb7-4954-ae3a-dfb360620954","ListId":"4ba4d24a-4774-485b-8954-92794088f690"}];
var id = obj[0].ItemId;
  • Thanks Md...managed to work it out from your prompt. Final solution updated above. – Stephen Jan 21 '14 at 12:06
  • How to get Related Item ID using c# ? – Imen Turki May 8 '15 at 8:45

For those who are trying the same using CSOM.

Step 1: First query the list in which the workflow is running with Item ID - 2

Step 2: Read the Field name which is created with your workflow name. 'VetriWorkFlow' is the workflow name and field name.


Step 3: In this field you will be able to see an instance id. Capture the same and pass it to 'WF4InstanceId' column in Workflow Tasks list.

Result: You will get the list of tasks that are created for the list item 2.

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.