first post and feeling a little lost at this point. I am trying to reproduce the result of Null in my json object. Currently the results produce the following:
{ overlapping_tradelines: false, time_for_overlap_months: 628, minimum_two_years_overlapping: false, version: '08.23.21' }
I would like for it to produce:
{ overlapping_tradelines: false, time_for_overlap_months: Null, minimum_two_years_overlapping: false, version: '08.23.21' }
I have tried to implement a second if statement with no avail. Would I need to implement the else if in order to get the results that I want to achieve? Here is my working code: *note the xml paths have been removed for ease of code. let me know if you would like the files to dig deeper :)
const jsonOutput = {};
let isOverLap = false;
let openDate = null;
let minimum_two_years_overlapping = false;
var stop = false;
for (let i = 1; i <= applicantSegLen; i++) {
if (stop == true) break;
const account = xpath.select("string(//TRsegments[1]/TRsegment[" + i + "]/@account)", doc);
const dateopen = xpath.select("string(//TRsegments[1]/TRsegment[" + i + "]/@dateopen)", doc);
const balance = xpath.select("string(//TRsegments[1]/TRsegment[" + i + "]/@balance)", doc);
for (let j = 1; j <= coApplicantSegLen; j++) {
if (stop == true) break;
const account2 = xpath.select("string(//TRsegments[1]/TRsegment[" + j + "]/@account)", coDoc);
const dateopen2 = xpath.select("string(//TRsegments[1]/TRsegment[" + j + "]/@dateopen)", coDoc);
const balance2 = xpath.select("string(//TRsegments[1]/TRsegment[" + j + "]/@balance)", coDoc);
if (account === account2 && dateopen === dateopen2 && balance === balance2) {
openDate = dateopen;
isOverLap = true;
stop = true;
}
}
}
//diff is the conversion for opendate to today's date. It converts milliseconds to months
jsonOutput["overlapping_tradelines"] = isOverLap;
const now = Date.now();
openDate = new Date(openDate);
let diff = now - openDate;
diff = diff / (30 * 24 * 60 * 60 * 1000);
const months = Math.floor(diff);
jsonOutput["time_for_overlap_months"] = months;
minimum_two_years_overlapping = diff == 24;
jsonOutput["minimum_two_years_overlapping"] = minimum_two_years_overlapping;
let version = "08.23.21";
jsonOutput["version"] = version;
console.log(jsonOutput);