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
Creating a If/Else Statement in JS which is dependant on a data attribute

So I have an app, which contains a button directing people to my 'Ccenter', normally this would bring me to a .DE domain, but I want to create the ability for it to redirect to the .AT instance of my site.

I can decide which domain the button should bring me to by looking at my recipient data, which always contains a country specific email address.

'recipient_email':data.ticket.recipient,

I thought the best way for this to work is an If/Else Statement on the Button itself, where I could use if “data.ticket.recipient.contains?(.de)” to ensure the button links to the .DE app instance, otherwise link to the .AT instance.

I'm unsure how to structure that statement within my code, and would appreciate some pointers or advice on if this is the best way to achieve what I'm aiming for.

Current code:

client.get(`ticket.customField:${cCenterCaseIdFieldName}`).then((result) => {
          updateDataPoints(result, data, cCenterCaseIdFieldName);
          const recipientEmail = data.ticket.recipient;
          const zendeskID = data.ticket.id;
          const cCenterUrlAustria = getAustrianCcenterUrl(zendeskID)
          const cCenterUrl = getCcenterUrl(zendeskID);
          const collapse = $('#collapseExample')
          $("#myBtnToCcenter").click(() => openModalPopup(cCenterUrl));
          $("#myBtnToAustrianCcenter").click(() => openModalPopup(cCenterUrlAustria));
         

Modal Pop Up Which Results From Button Click:

  function openModalPopup(locationUrl) {
  const modalOptions = {
    location: 'modal',
    url: locationUrl,
    size: {
      width:  '80vw',
      height: '80vh'
    }
  };
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

i guess you could just do sth. like this:

const recipientEmail = data.ticket.recipient;
var cCenterUrl;
if(recipientEmail.indexOf(".de") > 0) {
    cCenterUrl = getCcenterUrl(zendeskID);
}else{
    cCenterUrl = getAustrianCcenterUrl(zendeskID)
}
$("#myBtnToCcenter").click(() => openModalPopup(cCenterUrl));

and just use 1 button, if cCenterUrl can change during runtime, u cannot use const of course

about 4 years ago · Juan Pablo Isaza Denunciar

0

One way would be to get the correct URL first, then set the onClick handler accordingly. Something like:

var url = data.ticket.recipient.includes(".de") ? getCcenterUrl(zendeskID) : getAustrianCcenterUrl(zendeskID);

$("#myBtnToCcenter").click(() => openModalPopup(url));

Side note: The includes() function is case-sensitive. If you are not sure of the case (upper/lowercase) of the data.ticket.recipient string, then you can do

data.ticket.recipient.toLowerCase().includes(".de".toLowerCase())

instead of data.ticket.recipient.includes(".de").

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