0

How can I use the var EmployeeID on inside a const?

I have this JS script and get the EmployeeID using a fetch. I want to set the variable nmr_colaborador, which is inside the const, with the value of EmployeeID


<script>

var foto;
var EmployeeID;

fetch("URL", {
    method: 'GET',
    headers: {
        'Accept': 'application/json',
    },
})
.then(response => response.text())
.then(text => { 
    foto = JSON.parse(text)
    EmployeeID = foto.UserProfileProperties[110].Value
})


  const CHANNEL_TOKEN = 'token';
  const API_KEY = 'api key';
  const CONFIG = {
    environment: "production",
    display: {
      colors: {
        headerGradientStart: '#FFD100',
        headerGradientEnd: '#FFD100',
        headerLetters: 'light',
        sendMessageButton: '#152091',
      }
    },
    
    
    context_variables: {
      nmr_colaborador: EmployeeID
      
    }
  };

  })
</script>   

I have tried using async function and await, but I still can't get the value outside the fetch. What is the best way of doing this?

0 Answers0