Hi guys, just need some help few tweaks to my code the results is looping my items. I should have 6 items to display only but the results on the image below it got loop redundant here’s my code. repeated the all list of items twice or trice
![]()
async function loadDealsDetails2() {
try {
const dealsResponse = await fetch(
'https://transforminator.com/_hcms/api/congratsdeal',
requestOptions
)
const dealsData = await dealsResponse.json()
console.log(dealsData)
if (dealsData.length > 0) {
// Create a list of unique contact IDs
const contactsIds = dealsData.reduce((acc, curr) => {
const partnerContact = curr.associations.contacts.results.find(
(result) => result.type === 'partner_contact' || curr.associations.contacts.results[0]
)
return [...new Set([...acc, partnerContact.id])]
}, [])
// Create a list of all unique company IDs
const companiesIds = dealsData.reduce((acc, curr) => {
const partnerCompany = curr.associations.companies.results.find(
(result) => result.type === 'partner_company' || curr.associations.companies.results[0]
)
return [...new Set([...acc, partnerCompany.id])]
}, [])
// Create a list of deal owners
const dealOwnersIds = dealsData.map(({ properties }) => properties.hubspot_owner_id)
// Fetch contacts, companies, and owners details
const contactsDetails = await fetchObjectsDetails('contactdetails', contactsIds.join(','))
const companyiesDetails = await fetchObjectsDetails('companydetails', companiesIds.join(','))
const ownersDetails = await fetchObjectsDetails('ownerdetails', dealOwnersIds.join(','))
const userCompanyId = document.getElementById('companyId').value
if (dealsData.length > 0) {
const table = document
.getElementById('demoC')
.getElementsByTagName('tbody')[0]
const companyIdd = document.getElementById('companyId').value
dealsData.forEach((element) => {
const row = table.insertRow()
let cell = row.insertCell()
cell.innerHTML =
'<a class="hyper_linkhere_trigger_javascript" target="_blank" href="/deal-details?dealid=' +
element['id'] +
'">' +
element['properties']['dealname'] +
'</a>'
cell = row.insertCell()
cell.innerHTML =
getCompanyName(companyiesDetails, element['associations']['companies']['results'][0]['id'])
cell = row.insertCell()
cell.innerHTML = getOwnerDetails(ownersDetails, element['properties']['hubspot_owner_id'])
cell = row.insertCell()
cell.innerHTML = getContactDetails(contactsDetails, element['associations']['contacts']['results'][0]['id']).fullName
cell = row.insertCell()
cell.innerHTML = getLabelName(element['properties']['dealtype'])
cell = row.insertCell()
cell.innerHTML = '$' + element['properties']['amount']
cell = row.insertCell()
cell.innerHTML = getLabelName(element['properties']['dealstage'])
})
}
}
} catch (error) {
console.log('error', error)
}
}
loadDealsDetails()
loadDealsDetails2()
