Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!