Last active
August 31, 2021 06:51
-
-
Save anvilation/6563acb5165168275f300ec50cbb24fa to your computer and use it in GitHub Desktop.
You Might not need WebReoprts: When to use WebReports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', () => { | |
try { | |
main(); | |
} catch (error) { | |
console.error(error); | |
} | |
}); | |
async function main() { | |
// Constants | |
const formSettings = parseFuncValues(); | |
const otcsticket = LLCOOKIE || ''; | |
const basesupport = '/appimg/businessrequest'; | |
const constant = await getJSON(`${basesupport}/constants.json`); | |
const businessrequestValues = await getJSON(`${basesupport}/businessrequest.json`); | |
const categoryEl = document.getElementById('_1_1_2_1'); | |
const subCategoryEl = document.getElementById('_1_1_3_1'); | |
populateCategoryField(businessrequestValues, categoryEl); | |
categoryEl.addEventListener('change', function(e) { | |
let selectedCat = e.target.options[e.target.options.selectedIndex].text; | |
let subCatValues = businessrequestValues.filter(cat => { | |
if (cat.Category == selectedCat) { | |
return cat; | |
} | |
}) | |
if (subCatValues.length !== 0) { | |
populateSubCategoryField(subCatValues[0]['Sub-Category'], subCategoryEl); | |
} | |
categoryEl.setAttribute('readonly', true); | |
categoryEl.setAttribute('disabled', true); | |
}) | |
} | |
// Populate Drop Down | |
function populateCategoryField(values, catTarget,){ | |
catTarget.innerHTML = ''; | |
let option = document.createElement('option'); | |
option.innerText = 'Select Category'; | |
catTarget.appendChild(option); | |
for (let index = 0; index < values.length; index++) { | |
const value = values[index]; | |
let option = document.createElement('option'); | |
option.innerText = value.Category | |
catTarget.appendChild(option) | |
} | |
} | |
function populateSubCategoryField(subCatValues, subCatTarget){ | |
subCatTarget.innerHTML = ''; | |
let option = document.createElement('option'); | |
option.innerText = 'Select Category'; | |
subCatTarget.appendChild(option); | |
for (let index = 0; index < subCatValues.length; index++) { | |
const value = subCatValues[index]; | |
let option = document.createElement('option'); | |
option.innerText = value | |
subCatTarget.appendChild(option) | |
} | |
subCatTarget.removeAttribute('disabled'); | |
} | |
// Get Constants | |
async function getJSON(url) { | |
let response = await httpRequest('GET', url, null, null, null); | |
response = JSON.parse(response); | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment