Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Why am I unable to send a variable as URL in a Planner Task reference?

I am trying to set references for a task via the Planner Graph API, but am unable to set the URL through a variable.

I have written a separate method for encoding the url, and it returns the correct value, but still the references aren't 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

  }

But if I change encodedLink to the hardcoded URL (copied from the value set in the variable encodedLink), it works.

{
          references: {
            "https%3A//shmafe%2Esharepoint%2Ecom/sites/PlannerTest1/Delade dokument/nedladdning%2Ejpg" : {
              "@odata.type": "microsoft.graph.plannerExternalReference",
              "previewPriority": " !",
              type: "Other",
            },
          },
        }

I need to be able to set the link dynamically, so how can I do it without being able to use a variable? Am I doing something else wrong?

Microsft documenttion for Update plannertaskdetails https://docs.microsoft.com/en-us/graph/api/plannertaskdetails-update?view=graph-rest-1.0&tabs=javascript

Microsft documenttion for plannerExternalReferences resource type https://docs.microsoft.com/en-us/graph/api/resources/plannerexternalreferences?view=graph-rest-1.0

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To use a variable as an object key, you need to use the bracket syntax

For example:

const myVariable = 'hello';
const demoObject = {
  [myVariable]: 'world'
};

console.log(demoObject[myVariable]);
// same as
console.log(demoObject.hello);

This should fix it:

const updateAttachedFiles = (
    links: string[],
    taskId: string,
    etag: string
  ) => {
    var encodedLink: string; 
    links.forEach(async (link) => {
      encodedLink = encodeURI(link)
      await graph.planner.tasks.getById(taskId).details.update(
        {
          references: {
            [encodedLink] : {
              "@odata.type": "microsoft.graph.plannerExternalReference",
              "previewPriority": " !",
              type: "Other",
            },
          },
        },
        etag);
    }
  )
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda