0

I am trying to update Planner Task details checklist items using the GraphApi in C#. The checklist entries have an order already from the source I am reading from (simple line numbers, 1..N).

Microsoft defines OrderHints like this.

If I set the order hints like this 0001, 0002, 0003 ... and try to save the checklist I get an error saying Specified order hint is in an invalid format: The input (0001) does not contain spaces or exclamation points.. So I guess I can't use simple padded numbers ($"{lineNumber}".PadLeft(4, '0')).

I tried to put ! at the end, like 0001 !, 0002 !, 0003 ! ... and the api accepts the data that way, however the checklist entries are not in the order I meant to save them (just in a random order).

How can I generate new OrderHints for my entries?

private PlannerChecklistItems CheckListItemsFrom(SapPlannerSyncSalesOrder so)
{
    var checklistItems = new PlannerChecklistItems();
    var soRows = so.Rows;
    if (soRows.Count == 0) return checklistItems;

    for (var i = 0; i < soRows.Count; i++)
    {
        var row = soRows[i];
        //var orderHint = $"{i+1}".PadLeft(6, '0');

        var orderHint = new string('A', i + 1);

        var newId = Guid.NewGuid().ToString("D");

        checklistItems[newId] = new PlannerChecklistItem
        {
            Title = row.AsPlannerCheckListTitle(),
            IsChecked = row.IsClosed(),
            OrderHint = $"{orderHint}"
        };
    }

    return checklistItems;
}

Edit: I create the checklist items all at once. The plan this is for only uses the checklists to display sales order row statuses. So I just put the sale order rows in the checklist and mark them as checked if that part of the sales order is fulfilled (if the sales order row count <= 20).

If the sales order gets updated, I just re-create the checklist with new checklist items (delete the old ones by including them in the request, but setting their values to null). The checklist is not updated by hand, only the ERP can change a sales order.

Because the sales order dictates the row order, I always have a simple, numerical order number I would like the checklists to have (1,2,3...).

We use the planner browser client (https://tasks.office.com/) and the "random" order gets saved like this, If I save my checklist items with order hints like ! and ! !:

"TaskDetails": {
    "Checklist": {
      "383f824c-b37d-4ab7-85a2-384bddfaf787": {
        "Title": "... - 1,00 db",
        "OrderHint": "}sb",
        "IsChecked": false
      },
      "7b0d9498-84d5-497f-9151-f0714bd78d82": {
        "Title": ".... - 1,00 db",
        "OrderHint": "yI",
        "IsChecked": false
      },
      "7c36d659-1265-490a-824f-9e78d800bfa7": {
        "Title": "....) - 3,00 óra",
        "OrderHint": "}PM",
        "IsChecked": false
      },
      "9530040d-4c2b-4840-a8cc-eb0be43a801a": {
        "Title": "...... - 1,00 db",
        "OrderHint": "lF",
        "IsChecked": false
      },
      "98ddf050-7c0b-45fd-8935-3faa1780c3d5": {
        "Title": ".... - 95,00 km",
        "OrderHint": "}gE",
        "IsChecked": false
      },
      "b593e4ce-4c5a-4af3-b7c2-e7e77a7bd6c4": {
        "Title": ".... - 1,00 db",
        "OrderHint": "|P",
        "IsChecked": false
      },
      "c6467ec2-ab2e-4e50-9025-56fb73ddbe32": {
        "Title": ".... - 1,00 db",
        "OrderHint": "}I",
        "IsChecked": false
      },
      "eec0c0b9-aece-4d8e-a8f8-33cc21946a91": {
        "Title": "..... - 4,50 l",
        "OrderHint": "uo",
        "IsChecked": false
      },
      "f108c8fe-4147-4146-adeb-cfbfab6c1151": {
        "Title": ".... - 1,00 db",
        "OrderHint": "{M",
        "IsChecked": false
      },
      "f2e31196-d15e-48d3-baaf-cefe739f7dd5": {
        "Title": "....- 1,00 db",
        "OrderHint": "[K",
        "IsChecked": true
      }
},

Update 2:

The request to set the checklist looks like this (I manually converted the PlannerTaskDetails object to Json with JsonConvert.SerializeObject()):

{
  "Checklist": [
    {
      "Key": "7287165c-06cb-47df-bfed-269922a5b357",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": null,
        "LastModifiedDateTime": null,
        "OrderHint": " !",
        "Title": "(.... - Ny: 99,00 db / Ö: 100,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    },
    {
      "Key": "b5075d79-9f0a-4c1d-82aa-3f2fb40e1272",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": null,
        "LastModifiedDateTime": null,
        "OrderHint": " ! !",
        "Title": "(.... - 200,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    },
    {
      "Key": "4c2c0faf-f720-490a-a929-e4f235d4cec9",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": null,
        "LastModifiedDateTime": null,
        "OrderHint": " ! ! !",
        "Title": "....- 300,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    },
    {
      "Key": "9bffa151-f8fe-47fd-b52a-cae7b848266b",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": null,
        "LastModifiedDateTime": null,
        "OrderHint": " ! ! ! !",
        "Title": "... - 400,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    }
  ],
  "Description": "...",
  "PreviewType": 2,
  "References": [],
  "Id": "4Gzvx5f3r0K0M....",
  "ODataType": null,
  "AdditionalData": {
    "@odata.context": {
      "ValueKind": 3
    },
    "@odata.etag": {
      "ValueKind": 3
    }
  }
}

Calling code looks like this:

public async Task UpdatePlannerTaskDetails(
    string plannerTaskId, 
    string detailsEtag /* Details body has a different etag! */,
    PlannerTaskDetails taskDetails
)
{
    var client = await GetClient();
    await client
        .Planner
        .Tasks[plannerTaskId]
        .Details
        .Request()
        .Header("Prefer", "return=representation")
        .Header("If-Match", detailsEtag)
        .UpdateAsync(taskDetails);
}

Resulting details (captured the return of the UpdateAsync):

{
  "Checklist": [
    {
      "Key": "0bd81e93-b4cb-4426-812a-400a7e829166",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": {
          "Application": null,
          "Device": null,
          "User": {
            "DisplayName": null,
            "Id": "c21b0185-....",
            "AdditionalData": null,
            "ODataType": null
          },
          "AdditionalData": null,
          "ODataType": null
        },
        "LastModifiedDateTime": "2022-06-28T08:26:42.8180847+02:00",
        "OrderHint": "[i",
        "Title": ".... - 200,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    },
    {
      "Key": "0071647c-bd62-4102-8278-2a837ff1ec26",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": {
          "Application": null,
          "Device": null,
          "User": {
            "DisplayName": null,
            "Id": "c21b0185-....",
            "AdditionalData": null,
            "ODataType": null
          },
          "AdditionalData": null,
          "ODataType": null
        },
        "LastModifiedDateTime": "2022-06-28T08:26:42.8180847+02:00",
        "OrderHint": "8585452093426908086PY",
        "Title": ".... - Ny: 99,00 db / Ö: 100,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    },
    {
      "Key": "ad5572ca-ad2a-4e69-bf4c-24e039ca0cd9",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": {
          "Application": null,
          "Device": null,
          "User": {
            "DisplayName": null,
            "Id": "c21b0185-....",
            "AdditionalData": null,
            "ODataType": null
          },
          "AdditionalData": null,
          "ODataType": null
        },
        "LastModifiedDateTime": "2022-06-28T08:26:42.8180847+02:00",
        "OrderHint": "l^",
        "Title": ".... - 300,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    },
    {
      "Key": "c29e44cd-8404-4b65-bb5b-10cf1bda345c",
      "Value": {
        "IsChecked": false,
        "LastModifiedBy": {
          "Application": null,
          "Device": null,
          "User": {
            "DisplayName": null,
            "Id": "c21b0185-....",
            "AdditionalData": null,
            "ODataType": null
          },
          "AdditionalData": null,
          "ODataType": null
        },
        "LastModifiedDateTime": "2022-06-28T08:26:42.8180847+02:00",
        "OrderHint": "uy",
        "Title": ".... - 400,00 db",
        "AdditionalData": null,
        "ODataType": "#microsoft.graph.plannerChecklistItem"
      }
    }
  ],
  "Description": "....",
  "PreviewType": 2,
  "References": [],
  "Id": "4Gzvx5f3r0K0Mx41...",
  "ODataType": null,
  "AdditionalData": {
    "@odata.context": {
      "ValueKind": 3
    },
    "@odata.etag": {
      "ValueKind": 3
    }
  }
}

Somehow even the keys get changed after update.

The order displayed in planner: enter image description here

Usually, the order is just random, not reversed.

If I manually complete a checklist item and capture the request in the browser console, the checklist:

"TaskDetails": {
"Checklist": {
  "0071647c-bd62-4102-8278-2a837ff1ec26": {
    "Title": ".... - Ny: 99,00 db / Ö: 100,00 db",
    "OrderHint": "8585452093426908086PY",
    "IsChecked": true
  },
  "0bd81e93-b4cb-4426-812a-400a7e829166": {
    "Title": ".... - 200,00 db",
    "OrderHint": "[i",
    "IsChecked": false
  },
  "ad5572ca-ad2a-4e69-bf4c-24e039ca0cd9": {
    "Title": "... - 300,00 db",
    "OrderHint": "l^",
    "IsChecked": false
  },
  "c29e44cd-8404-4b65-bb5b-10cf1bda345c": {
    "Title": ".... - 400,00 db",
    "OrderHint": "uy",
    "IsChecked": false
  }
},
"CompletedBy": null,
"Description": "...",
"PreviewType": 2,
"References": {},
"Id": "4Gzvx5f3r0K0Mx....",
"ItemVersion": 6,
"Type": 2
},
5
  • Can you share the request that produces the output in the question? Without having the request and the corresponding result, it is not possible to tell what is wrong. Jun 27, 2022 at 17:50
  • @TarkanSevilmis Updated the question with details.
    – szab.kel
    Jun 28, 2022 at 6:41
  • That request and response don't match, as the keys cannot change. I'm assuming the response is to an identical request. In the request the order is "Ny 99 ...", "200 db", "300 db", "400 db", which get order hints "85...", "[i", "l^", "uy". When sorted these match exactly the order in the request. The UI is displaying them in reverse order, but this still would allow for the desired UX order (you could submit Space+!, then Space+ Space + ! + ! for the reverse sorting). If you have an example where the order doesn't match, please provide that, but the current example is working as expected. Jun 30, 2022 at 17:20
  • @TarkanSevilmis The response values are returned by the same UpdateAsync I used to update the values with. Yes, the checklist ids changed. There were no identical request, this was the only one (I mean, using debug mode I couldn't even capture a different response). Also, the order is not just reverse, most of the checklists I updated have random order.
    – szab.kel
    Jul 1, 2022 at 5:21
  • The ids of checklists are client specified and are preserved as is. The service does not have the capability to generate or change those identifiers. If you are seeing them not match when you look at the request/response, there may be some cache or something else interfering with what you see, which could also explain the appearance of distorted order. I'd recommend using a network trace tool, such as Fiddler (from Telerik) to see what is actually being sent and received, which should help trace where the issue is. Jul 1, 2022 at 18:04

2 Answers 2

0

OrderHints are server generated. As described in the article you've linked, ! will generate a order hint without any values. The general mechanic is the server accepts this input: <previous item's orderHint> + <space> + <next item's orderHint> + !. This would have the server generate an order hint such that the generated value places the item between the previous and the next item. Either order hint value can be empty, indicating the previous or the next item doesn't exist (e.g. item is to be placed at the top or the bottom).

The order hints are composable, as in the uncalculated values can be used as order hints in other input. For example, for your case, first item can have " !", as it is being placed without any other items (e.g. both previous and next items are empty). The next item would be placed after the first one, which can be expressed as the previous item order hint " !" + space + next item order hint (=empty) + !, producing " ! !". The item after that similarly gets " ! ! !". When the request is submitted to the server, the generated values will sort correctly.

A common problem people are having is that the order hints must be sorted with "case sensitive ordinal sorting", which uses the ASCII values of the characters to sort the strings. Some languages, when using default string sort mechanisms use language specific sorting, which produces the incorrect order.

3
  • I tried to use order hints with spaces and exclamation points only, but it does not work. The checklist items are still in a random order. checklistItems[newId].OrderHint = new StringBuilder().Insert(0, " !", index + 1).ToString();
    – szab.kel
    Jun 24, 2022 at 6:10
  • Can you share what you passed in and what the resulting order hints are? Also where are you viewing the checklist in custom code or in some Planner UX (Web, Teams or Mobile)? Are you creating checklist items all at once in a single request, or in different requests? Jun 24, 2022 at 17:19
  • I updated my question with the details. Basically I send them at once with ` !` for the first item, ` ! !` for the second and so on and I get "random" }sb, yI, }pm...
    – szab.kel
    Jun 27, 2022 at 6:18
0

I know this is old but I recently dealt with this problem.

Excuse me for posting in javascript when the question was in C# but there is little information out there on the topic.

You need to sort the checklists by string ordinal as was mentioned by @Tarkan Sevilmis to get the correct order. I would upvote his answer but my lack of reputation and being new precludes that. Be wary of viewing in console with the original GUID/UUID as they will always appear in UUID order now matter how much you sort (I fell into that trap for hours). In this instance I renamed the id to store in the correct order.

// Sort Checklist Items In Reverse Order by OrderHint
// Have To Rename the ID To Avoid Auto Sort Of Objects
for (d = 0; d < planTemplates[templateIndex].details.length; d++)
{
    if (Object.keys(planTemplates[templateIndex].details[d].checklist).length > 0)
    {
        copyChecklist = Object.entries(planTemplates[templateIndex].details[d].checklist);
        copyChecklist.sort((a, b) => (a[1].orderHint < b[1].orderHint ? -1 : 1));

        planTemplates[templateIndex].details[d].checklist = {};

        for ( i = 0; i < copyChecklist.length; i++)
        {                
            newChecklist = {
                [i]:
                    {
                        "@odata.type": "#microsoft.graph.plannerChecklistItem",
                        isChecked: copyChecklist[i][1].isChecked,
                        title: copyChecklist[i][1].title,
                        orderHint: copyChecklist[i][1].orderHint,
                        lastModifiedBy: copyChecklist[i][1].lastModifiedBy,
                        lastModifiedDateTime: copyChecklist[i][1].lastModifiedDateTime
                    }
            }
            Object.assign(planTemplates[templateIndex].details[d].checklist, newChecklist);
        }
        newChecklist = {};
    }
}

If you are bulk patching in checklists you can follow the documentation for using order hints on an empty list here.

In an empty list you just need to specify the first item's order hint as " !" then every item in order append another " !"

references = {};
   checklistItem = {};
   newChecklist = {};
   previousOrderHint = ' !';

    if (Object.keys(planTemplates[templateIndex].details[d].references).length > 0)
    {
        references = {
            [Object.entries(planTemplates[templateIndex].details[d].references)[0]]:
                {
                    "@odata.type": "#microsoft.graph.plannerExternalReference",
                    alias: Object.entries(planTemplates[templateIndex].details[d].references)[0][1].alias,
                    type: Object.entries(planTemplates[templateIndex].details[d].references)[0][1].type,
                    previewPriority: " !",
                }
        }
    }

    if (Object.keys(planTemplates[templateIndex].details[d].checklist).length > 0)
    {
        copyChecklist = Object.entries(planTemplates[templateIndex].details[d].checklist);
        for ( i = 0; i < copyChecklist.length; i++)
        {
            checklistItem = {
                [generateUUID()]:
                    {
                        "@odata.type": "#microsoft.graph.plannerChecklistItem",
                        isChecked: copyChecklist[i][1].isChecked,
                        title: copyChecklist[i][1].title,
                        orderHint: previousOrderHint
                    }
            }
            Object.assign(newChecklist , checklistItem);
            previousOrderHint = previousOrderHint + ' !';
        }
    }


    plannerDetails = {
        previewType: previewType,
        description: description,
        references: references,
        checklist: newChecklist

    }

The API will then add the checklist items in bulk in the order specified.

Hope this helps others searching for answers on bulk adding checklists and how to deal with the order hints.

The link above on order hints gives very good examples on how to insert items before and after existing order hints.

Regards,

Your Answer

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

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