Issue with multiple popup lists not populating in custom dialog
Essentially I'm trying to pull two different lists into two separate dialog "popup" lists but for some reason only one of the lists will populate at a time. I'm doing all this in a folder level script and I am unable to change that. The data is being pulled from a proprietary application. My code is below, please let me know if there's anything obviously wrong with it or if clarification is needed.
function newElement(type, id, name, elements) {
var ele = {};
if (elements === undefined) {
elements = 0
}
switch (type) {
case "radio":
ele = { type: type, item_id: id, group_id: 'grup', name: name };
break;
case "check_box":
ele = { type: type, item_id: id, name: " " + name };
break;
case "edit_text":
ele = { type: type, item_id: id, name: name };
break;
case "popup":
ele = { type: type, item_id: id, name: name, char_width: 10 };
break;
case "static_text":
ele = { type: type, alignment: id, name: name };
break;
case "cluster":
ele = { type: type, align_children: id, name: name, elements: elements };
break;
}
return ele;
}
function initState(type, list, id, pupList) {
if (pupList === undefined) pupList = {};
var state = {};
switch (type) {
case "check_box":
for (var i = 0; i < list; i++) {
state[id + i] = false;
}
break;
case "radio":
for (var i = 0; i < list; i++) {
state[id + i] = false;
}
break;
case "edit_text":
for (var i = 0; i < list; i++) {
state[id + i] = "";
}
break;
case "popup":
for (var i = 0; i < list; i++) {
state[id + i] = pupList;
}
break;
}
return state;
}
//PLEASE NOTE ALL THE VARIABLES ARE FROM AN EXTERNAL SOFTWARE
var repList = {};
for (var i = 0; i < m.heirReps.number; i++) {
//making integer values odd so doesn't conflict with relationship list
if (i === 0) {
j = 1;
} else {
j += 2
}
repList[m.heirReps.name[i]] = j * -1;
}
var repInit = initState("popup", finHeirList.number, "fan", repList); //representative
var disInit = initState("check_box", finHeirList.number, "dis"); //disability
var plzInit = {};
for (i = 0; i < finHeirList.number; i++) {
plzInit["plz" + i] = {
"Son": -2,
"Daughter": -4,
"Grandson": -6,
"Granddaughter": -8,
"Brother": -10,
"Sister": -12,
"Father": -14,
"Mother": -16,
"Niece": -18,
"Nephew": -20
}
}
var finRes = {}
var finDlg = {
initialize: function (e) {
e.load(plzInit, repInit, disInit);
},
commit: function (e) {
finRes = e.store();
},
description: {
type: "view",
elements: [
{
type: "view",
elements: [
{
type: "static_text",
name: "Fill out relevant information for each heir."
},
{
type: "view",
elements: []
},
{
type: "ok_cancel"
}
]
}
]
}
};
for (var i = 0; i < finHeirList.number; i++) {
var plzEle = newElement("popup", "plz" + i, "Relationship: ");
var disEle = newElement("check_box", "dis" + i, "Under legal disability");
var repEle = newElement("popup", "fan" + i, "Representative");
//Created these 2 clusters because for some reason the name of the popup elements doesn't work for me -_-
var repCluster = newElement("cluster", "align_fill", "Select a representative", [repEle])
var plzCluster = newElement("cluster", "align_fill", "Indicate the heir's relationship to the decedent", [plzEle])
finDlg.description.elements[0].elements[1].elements.push(newElement("cluster", "align_fill", finHeirList.name[i], [plzCluster, repCluster, disEle]));
}
if (finHeirList.number > 0) {
app.execDialog(finDlg);
}
for (var i = 0; i < finHeirList.number; i++) {
for (x in finRes["plz" + i]) {
if (finRes["plz" + i][x] > 0) {
var plz = x;
break;
}
}
for (y in finRes["fan" + i]) {
if (finRes["fan" + i][x] > 0) {
var fan = x;
break;
}
}
console.println("Relationship, Rep, Disability - " + finHeirList.name[i] + ": " + plz + ", " + fan + ", " + finRes["dis" + i]);
}
Result is that the relationship popup populates fine while the rep one does not. When I instead put the rep popup first in the for loop the relationship popup stops working. I thought maybe it had something to do with the cluster not allowing them to be together but I separated them into different clusters and it still isn't working correctly.
All advice is greatly appreciated.
