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

229
Views
javascript: detect which variable changed its value

Given that I have the following condition to check whether a couple of variables value have changed.

<%
if (ctx.recipient.@firstName != ctx.recipient.@firstName_init || ctx.recipient.@lastName != ctx.recipient.@lastName_init || ctx.recipient.@emailPreferredName != ctx.recipient.emailPreferredName_init) 
    {       
        document.controller.setValue('/ctx/vars/piiChanges',1);     
    }
%>

How can I detect which of all the 3 conditions value changed?

Here is my XML payload

<recipient JOB_TITLE="" 
       blackListEmail="0" 
       cmOneID="0" 
       company="" 
       email="dummy@dummy.com1" 
       emailPreferredName="Dummy1" 
       firstName="Dummy1" 
       id="13246096" 
       initiative="" 
       investorType="" 
       jurisdiction="" 
       lastName="Dummy1" 
       lawfulBasisLabel="None" 
       lawfulBasisName="none" 
       leadScore="0" 
       origin="" 
       status="0" 
       statusLabel="Other" 
       statusName="other" 
       _operation="update" 
       _key="@id" 
       firstName_init="Dummy" 
       lastName_init="Dummy" 
       email_init="dummy@dummy.com" 
       emailPreferredName_init="Dummy" 
       blackListEmail_init="0">
<postalAddress addrDefined="0"/>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could loop through the data object's properties and get a list of all of the keys that have changed. Something like this:

function getChangedProperties(recipient) {
  const changedProps = [];

  // Loop over each of the property keys of the recipient object
  Object.keys(recipient).forEach(key => {
    // Check non-init values to see if their init counterparts are equal
    if (!key.endsWith("_init") && recipient[`${key}_init`] !== recipient[key]) {
      changedProps.push(key);
    }
  });

  return changedProps;
}
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!