Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda