I've encountered an issue while attempting to set references for a task through the Planner Graph API. The problem arises when trying to set the URL using a variable.
Even though I have created a separate method to encode the URL, which successfully returns the correct value, the references are not being properly set for the Planner task.
const updateAttachedFiles = (
links: string[],
taskId: string,
etag: string
) => {
var encodedLink: string;
links.forEach(async (link) => {
encodedLink = escapeHtml(link)
await graph.planner.tasks.getById(taskId).details.update(
{
references: {
encodedLink : {
"@odata.type": "microsoft.graph.plannerExternalReference",
"previewPriority": " !",
type: "Other",
},
},
},
etag);
}
)
};
const escapeHtml = (unsafe) => {
let temp = unsafe.replaceAll("%", "%25")
unsafe = temp
.replaceAll(".", "%2E")
.replaceAll(":", "%3A")
.replaceAll("@", "%40")
.replaceAll("#", "%23");
return unsafe
}
However, if I manually replace encodedLink with the hardcoded URL (taken from the variable), it functions as expected.
{
references: {
"https%3A//shmafe%2E.sharepoint%2E.com/sites/PlannerTest1/Delade dokument/nedladdning%2E.jpg" : {
"@odata.type": "microsoft.graph.plannerExternalReference",
"previewPriority": " !",
type: "Other",
},
},
}
I need the ability to dynamically set the link, so how can I achieve this without using a variable? Is there something else that I am missing in my approach?
For further reference, you can check out the Microsoft documentation on updating Planner task details here.
Additionally, information about the plannerExternalReferences resource type can be found in the Microsoft documentation here.