// Use 'let' to allow reassignment of selectedEvent
let selectedEvent = typeof eventName === 'string' ? eventName : ''; // Declaring selectedEvent here with 'let'
console.log("Previous Selected Event:", selectedEvent); // Log the previous selected event
console.log("New Event Name:", newEvent);
const previousEventIndex = ticketworkflowconditions.findIndex(cond => cond.eventName === selectedEvent);
if (previousEventIndex !== -1) {
ticketworkflowconditions.splice(previousEventIndex, 1);
console.log(`Removed existing condition for event: "${selectedEvent}"`);
}
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new condition for the newly selected event
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
ticketworkflowconditions.push(newCondition);
console.log(`Added new condition for: "${newEvent}"`);
// Create new containers for fields and choices
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container');
newDropdownSet.appendChild(fieldNameContainer);
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
newDropdownSet.appendChild(choicesContainer);
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container');
buttonContainer.style.marginTop = '25px';
newDropdownSet.appendChild(buttonContainer);
// Populate fields based on the new event's context
await fieldschoosingvalues(newEvent, fieldNameContainer, choicesContainer, buttonContainer, newDropdownSet, null, null);
// Log the updated state of ticketworkflowconditions
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
// Update the selected event after the change
selectedEvent = newEvent; // Reassign selectedEvent here
});
// Append the newDropdownSet to the eventContainer
eventContainer.appendChild(newDropdownSet);
ticketworkflowContainer.appendChild(eventContainer);
}
async function fieldschoosingvalues(selectedEventValue, fieldNameContainer, choicesContainer, buttonContainer, container, selectedFieldName = null, selectedChoices = null) {
if (!selectedEventValue) {
console.error("fieldschoosingvalues called with an undefined selectedEventValue.");
return;
}
try {
let statusResp = await makeApiCall(apiKeyInput1.value, domainInput1.value);
// Select the current selected field if available
if (selectedFieldName && field.name === selectedFieldName) {
option.setAttribute('selected', 'selected');
}
});
fieldNameContainer.appendChild(fieldDropdown);
if (selectedFieldName) {
const selectedField = fields.find(field => field.name === selectedFieldName);
if (selectedField) {
await showingitschoices(choicesContainer, selectedField, selectedEventValue, selectedFieldName, buttonContainer, container, fieldNameContainer, selectedChoices);
} else {
console.error('Field not found in Dropdown');
}
}
// Find the event condition for the selected event name
const eventCondition = ticketworkflowconditions.find(cond => cond.eventName === selectedEventValue);
if (eventCondition) {
const previousFieldName = selectedFieldName; // Store the previous selected field name
// Log the previous field name for debugging
console.log(`Previous field name: ${previousFieldName}`);
if (previousFieldName && previousFieldName !== newSelectedFieldName) {
// Don't replace, just add new values
if (!eventCondition.fields) {
eventCondition.fields = {};
}
eventCondition.fields[newSelectedFieldName] = null; // Add the new field with a placeholder value (null)
console.log(`Added new field "${newSelectedFieldName}" to event condition.`);
}
// Clear the choices container before adding new choices
choicesContainer.innerHTML = '';
const newSelectedField = fields.find(field => field.name === newSelectedFieldName);
if (newSelectedField) {
await showingitschoices(choicesContainer, newSelectedField, selectedEventValue, newSelectedFieldName, buttonContainer, container, fieldNameContainer);
} else {
console.error('Field not found in Dropdown');
}
}
if (selectedChoices && selectedChoices.includes(String(choice.id))) {
option.setAttribute('selected', 'selected');
}
});
// Append the choices dropdown to the container
choicesContainer.appendChild(choicesDropdown);
// Listen for changes in the choices selection
choicesDropdown.addEventListener('fwChange', (event) => {
const selectedChoiceId = event.target.value;
code
// Find the event condition for the selected event name
let eventCondition = ticketworkflowconditions.find(cond => cond.eventName === selectedEventValue);
if (!eventCondition) {
eventCondition = { eventName: selectedEventValue, isEnabled: true, fields: {} };
ticketworkflowconditions.push(eventCondition);
}
// Update the fields object with the selected choice
if (!eventCondition.fields) {
eventCondition.fields = {};
}
eventCondition.fields[selectedFieldName] = selectedChoiceId;
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
});
// Add a button to create additional fields and choices
const addButton = document.createElement('button');
addButton.textContent = 'Add New Field & Choices';
addButton.classList.add('btn', 'btn-primary', 'mt-3'); // Styling the button
// Button event listener to add new fields and choices dropdowns
addButton.addEventListener('click', () => {
createAdditionalDropdowns(container);
});
// Append the add button to the button container
buttonContainer.appendChild(addButton);
}
// Function to create additional dropdowns dynamically
function createAdditionalDropdowns(container) {
// Create new containers for field name, choices, and button
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container', 'offset-md-2');
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container', 'mt-3');
// Append new containers to the main container
container.appendChild(fieldNameContainer);
container.appendChild(choicesContainer);
container.appendChild(buttonContainer);
// Call fieldschoosingvalues to populate new dropdowns
fieldschoosingvalues(
container.querySelector('.event-name-dropdown').value,
fieldNameContainer,
choicesContainer,
buttonContainer,
container
);
i choosed a event and choosed field and choices.now if i need to add another event with same
Assistant
To add a new event with the same field and choices after selecting an event and its corresponding fields and choices, you can modify your existing implementation. This involves copying the current field and choice configurations to a new event when creating an additional event condition.
You will need to create a new function or modify the existing addNewRule function slightly to handle this. Below is a modified version of your addNewRule function that includes functionality for adding another event with the same fields and choices.
// Use 'let' to allow reassignment of selectedEvent
let selectedEvent = typeof eventName === 'string' ? eventName : ''; // Declaring selectedEvent here with 'let'
To ensure that adding a new event with the same name (for instance, "Ticket Create") does not overwrite the existing event's fields and choices but instead creates a new entry in the workflowConditions, you need to revise the logic in the addNewRule function. The current logic removes the previous event condition if the same event name is selected, leading to overwriting.
Solution
Remove Deletion Logic: Instead of deleting the previous condition from ticketworkflowconditions, you should just add a new condition even if it shares the same event name. This change ensures that multiple conditions can exist for the same event name.
Store Conditions: When you detect that a condition already exists for a given event name, instead of removing it, you can simply create and add a new condition with the same name.
Here is the modified addNewRule function:
javascript
User
it can contain same event name but adding value should be respective to its set
Assistant
To allow multiple event conditions with the same event name but ensure that the values for fields and choices are tied to their respective sets, you can update the logic to make sure the fields and choices are managed independently for each event condition.
Goals
Each event condition can share the same event name.
Each condition maintains its independent set of fields and choices.
When a user adds fields and choices for an event, they should be stored within the scope of that specific event's condition.
Implementation
To achieve this, you need to slightly modify the event handling logic within the addNewRule function as well as any related functions that manage choices and fields.
Here's a basic outline of how you can structure the code:
Maintain Separate Fields for Each Event: When you create a new event, ensure that the fields and choices are stored in a way that they correspond to the specific instance of that event.
Improve the Field and Choice Adding Logic: Ensure that each time you create a field and choice set, it only affects the current instance of the event and doesn't interfere with others.
Modified addNewRule Function
Below is a modified version of your addNewRule function and relevant sections of your logic:
now i choosed group 5 ok. then i create same event and choose priority 5 this priority is adding to 1st set that should not did you understand
Assistant
Thank you for clarifying your requirements regarding how the data structure and interaction should behave. Based on your explanation, it seems you want to ensure that when creating multiple conditions for the same event (e.g., "TicketCreate"), each condition should independently manage its own set of fields and values. Specifically, if you select a field from one condition, it should not overwrite or interfere with fields from another condition that shares the same event name.
Objective
You can select the same event multiple times.
Each selection creates a separate condition that manages an independent set of fields and values.
For example, if the first condition has the field group set to 5, and the second condition sets priority to 3, these should be stored independently without any overlap.
Implementation Update
Modify how you handle the configuration for your event conditions so that they are uniquely tied to the instance where they are created.
Ensure that each event can have its respective fields and choices stored independently without affecting others.
Here’s how you could implement this:
Revised Approach
Change Structure of Event Conditions: While the eventName can be the same, each condition should be treated as a separate instance.
Independent Field Handling: When a field is selected, it is stored in the context of its specific event condition without affecting other conditions.
Example Code
Below is an updated implementation of the addNewRule function and related methods that ensures conditions are handled independently.
javascript
User
iparams.js:595 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'push')
at r. (iparams.js:595:26)
at tt (p-d6a83339.js:1:7102)
at Object.emit (p-d6a83339.js:1:6989)
at ct.fwSelectedHandler (p-9671b6e8.entry.js:1:18736)
at r. (p-d6a83339.js:1:677)
at tt (p-d6a83339.js:1:7102)
at Object.emit (p-d6a83339.js:1:6989)
at f.onValueChange (p-9671b6e8.entry.js:1:4774)
at p-d6a83339.js:1:11159
at Array.map ()
fix this error
Assistant
The error message you're encountering indicates that there is an attempt to call the .push() method on an undefined variable, which suggests that the variable you expect to be an array is not initialized before trying to use it. To effectively resolve this issue, we need to ensure that the workflows or conditions array is correctly initialized and that you're pushing new conditions into the right array.
Here’s how you can troubleshoot and fix this issue step-by-step:
1. Check Initialization of workflowConditions
Make sure that the workflowConditions variable is initialized as an empty array before you start using it to store conditions:
javascript
let workflowConditions = []; // Initialize workflowConditions as an empty array
2. Proper Scoping
Ensure that workflowConditions is defined in a scope that is accessible to the function where you're trying to push new conditions (like in addNewRule). If workflowConditions is a parameter being passed to addNewRule, ensure that it's always an array before you start pushing to it.
3. Correct Event Handling
From the error stack trace, it seems that the issue occurs when you're changing an event in a dropdown (likely when dealing with event handling related to the dropdown fw-select).
Confirm that you're pushing to workflowConditions correctly in the event handler section. Here’s a snippet of how it should look based on your previous code:
javascript
eventSelect.addEventListener('fwChange', async () => {
const newEvent = eventSelect.value;
// Check that workflowConditions is initialized
if (!Array.isArray(workflowConditions)) {
console.error("workflowConditions is not initialized as an array.");
return; // Return early to prevent errors
}
console.log("Selected Event:", newEvent);
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new independent condition for the selected event
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
workflowConditions.push(newCondition); // Safe to push because we checked for array
console.log(`Added new condition for: "${newEvent}"`);
// The rest of your logic...
});
User
async function loadExistingWorkflowConditions() {
4. let workflowConditions = alldata.ticket_workflow_conditions;
5. console.log("Mapping Data for Workflows:", workflowConditions);
6.
7. // Make sure you're passing both eventName and workflowConditions
8. // You should call the function for each workflow condition, so you can loop over the workflowConditions array and pass the eventName for each one.
9.
10. for (let condition of workflowConditions) {
11. await addNewRule(condition.eventName, workflowConditions); // Pass both eventName and workflowConditions
12. }
13. }
14.
15. let ticketworkflowconditions = [];
16.
17. async function addNewRule(eventName, workflowConditions) {
18.
19. console.log("Existing Workflow Conditions:", workflowConditions);
20.
21. const ticketworkflowContainer = document.getElementById('ticketworkflow-container');
22.
23. const eventContainer = document.createElement('div');
24. eventContainer.classList.add('event-container');
25. eventContainer.style.boxShadow = '0 5px 10px 0 rgba(0, 0, 0, 0.2)';
26. eventContainer.style.padding = '30px';
27. eventContainer.style.marginBottom = '15px';
28. eventContainer.style.borderRadius = '5px';
29. eventContainer.style.backgroundColor = '#fff';
30.
31. const newDropdownSet = document.createElement('div');
32. newDropdownSet.classList.add('row', 'ticketworkflow-dropdown');
33.
34. // Use 'let' to allow reassignment of selectedEvent
35. let selectedEvent = typeof eventName === 'string' ? eventName : ''; // Declaring selectedEvent here with 'let'
36.
37. newDropdownSet.innerHTML = 38. <div class="col-md-2 event-name-container"> 39. <fw-select 40. class="event-name-dropdown" 41. label="Select Event Name" 42. required="true" 43. placeholder="Your choice" 44. hint-text="Select singular option"> 45. <fw-select-option value="TicketCreate" ${selectedEvent === "TicketCreate" ? "selected" : ""}>Ticket Create</fw-select-option> 46. <fw-select-option value="TicketUpdate" ${selectedEvent === "TicketUpdate" ? "selected" : ""}>Ticket Update</fw-select-option> 47. <fw-select-option value="TicketCreateandUpdate" ${selectedEvent === "TicketCreateandUpdate" ? "selected" : ""}>Ticket Create and Update</fw-select-option> 48. </fw-select> 49. </div> 50. ;
51.
52. const eventSelect = newDropdownSet.querySelector('.event-name-dropdown');
53.
54. eventSelect.addEventListener('fwChange', async () => {
55. const newEvent = eventSelect.value;
56.
57. console.log("Previous Selected Event:", selectedEvent); // Log the previous selected event
58.
59. console.log("New Event Name:", newEvent);
60.
61. const previousEventIndex = ticketworkflowconditions.findIndex(cond => cond.eventName === selectedEvent);
62.
63. if (previousEventIndex !== -1) {
64. ticketworkflowconditions.splice(previousEventIndex, 1);
65. console.log();
66. }
67.
68. // Clear existing field-related containers
69. newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
70.
71. // Create a new condition for the newly selected event
72. const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
73. ticketworkflowconditions.push(newCondition);
74. console.log();
75.
76. // Create new containers for fields and choices
77. const fieldNameContainer = document.createElement('div');
78. fieldNameContainer.classList.add('col-md-2', 'field-name-container');
79. newDropdownSet.appendChild(fieldNameContainer);
80.
81. const choicesContainer = document.createElement('div');
82. choicesContainer.classList.add('col-md-2', 'choices-container');
83. newDropdownSet.appendChild(choicesContainer);
84.
85. const buttonContainer = document.createElement('div');
86. buttonContainer.classList.add('col-md-3', 'button-container');
87. buttonContainer.style.marginTop = '25px';
88. newDropdownSet.appendChild(buttonContainer);
89.
90. // Populate fields based on the new event's context
91. await fieldschoosingvalues(newEvent, fieldNameContainer, choicesContainer, buttonContainer, newDropdownSet, null, null);
92.
93. // Log the updated state of ticketworkflowconditions
94. console.log();
95.
96. // Update the selected event after the change
97. selectedEvent = newEvent; // Reassign selectedEvent here
98. });
99.
100. // Append the newDropdownSet to the eventContainer
101. eventContainer.appendChild(newDropdownSet);
102. ticketworkflowContainer.appendChild(eventContainer);
103. }
104.
105. async function fieldschoosingvalues(selectedEventValue, fieldNameContainer, choicesContainer, buttonContainer, container, selectedFieldName = null, selectedChoices = null) {
106. if (!selectedEventValue) {
107. console.error("fieldschoosingvalues called with an undefined selectedEventValue.");
108. return;
109. }
110.
111. try {
112. let statusResp = await makeApiCall(apiKeyInput1.value, domainInput1.value);
113.
114. if (statusResp && statusResp.ticket_fields) {
115. const fields = statusResp.ticket_fields.filter(field =>
116. field.field_type.startsWith('default_') &&
117. field.choices &&
118. field.choices.length > 0
119. );
120.
121. if (selectedFieldName) {
122. const fieldContainer = document.createElement('div');
123. fieldContainer.classList.add('field-container');
124. fieldNameContainer.appendChild(fieldContainer);
125.
126. const choicesDiv = document.createElement('div');
127. choicesDiv.classList.add('choices-container');
128. choicesContainer.appendChild(choicesDiv);
129.
130. await getFieldnamesfrom1stapi(fieldContainer, fields, choicesDiv, selectedEventValue, buttonContainer, container, selectedFieldName, selectedChoices);
131. } else {
132. await getFieldnamesfrom1stapi(fieldNameContainer, fields, choicesContainer, selectedEventValue, buttonContainer, container);
133. }
134. } else {
135. console.error('No fields found or data not available');
136. }
137. } catch (error) {
138. console.error("Error fetching data for Dropdown:", error);
139. }
140. }
141.
142. async function getFieldnamesfrom1stapi(fieldNameContainer, fields, choicesContainer, selectedEventValue, buttonContainer, container, selectedFieldName = null, selectedChoices = null) {
143. if (!selectedEventValue) {
144. console.error("Select an event before proceeding.");
145. return;
146. }
147.
148. const fieldDropdown = document.createElement('fw-select');
149. fieldDropdown.classList.add('field-name-dropdown');
150. fieldDropdown.setAttribute('label', 'Ticket Fields');
151. fieldDropdown.setAttribute('required', 'true');
152. fieldDropdown.setAttribute('placeholder', 'Choose a field');
153. fieldDropdown.setAttribute('hint-text', 'Select singular option');
154.
155. fields.forEach(field => {
156. const option = document.createElement('fw-select-option');
157. option.setAttribute('value', field.name);
158. option.textContent = field.label;
159. fieldDropdown.appendChild(option);
160.
161. // Select the current selected field if available
162. if (selectedFieldName && field.name === selectedFieldName) {
163. option.setAttribute('selected', 'selected');
164. }
165. });
166.
167. fieldNameContainer.appendChild(fieldDropdown);
168.
169. if (selectedFieldName) {
170. const selectedField = fields.find(field => field.name === selectedFieldName);
171. if (selectedField) {
172. await showingitschoices(choicesContainer, selectedField, selectedEventValue, selectedFieldName, buttonContainer, container, fieldNameContainer, selectedChoices);
173. } else {
174. console.error('Field not found in Dropdown');
175. }
176. }
177.
178. fieldDropdown.addEventListener('fwChange', async (event) => {
179. const newSelectedFieldName = event.target.value;
180.
181. // Find the event condition for the selected event name
182. const eventCondition = ticketworkflowconditions.find(cond => cond.eventName === selectedEventValue);
183.
184. if (eventCondition) {
185. const previousFieldName = selectedFieldName; // Store the previous selected field name
186.
187. // Log the previous field name for debugging
188. console.log();
189.
190. if (previousFieldName && previousFieldName !== newSelectedFieldName) {
191. // Don't replace, just add new values
192. if (!eventCondition.fields) {
193. eventCondition.fields = {};
194. }
195. eventCondition.fields[newSelectedFieldName] = null; // Add the new field with a placeholder value (null)
196. console.log();
197. }
198.
199. // Clear the choices container before adding new choices
200. choicesContainer.innerHTML = '';
201.
202. const newSelectedField = fields.find(field => field.name === newSelectedFieldName);
203. if (newSelectedField) {
204. await showingitschoices(choicesContainer, newSelectedField, selectedEventValue, newSelectedFieldName, buttonContainer, container, fieldNameContainer);
205. } else {
206. console.error('Field not found in Dropdown');
207. }
208. }
209. });
210. }
211.
212. async function showingitschoices(choicesContainer, selectedField, selectedEventValue, selectedFieldName, buttonContainer, container, fieldNameContainer, selectedChoices = null) {
213. choicesContainer.innerHTML = ''; // Clear existing content
214.
215. // Create the choices dropdown
216. const choicesDropdown = document.createElement('fw-select');
217. choicesDropdown.classList.add('choices-dropdown');
218. choicesDropdown.setAttribute('label', );
219. choicesDropdown.setAttribute('required', 'true');
220. choicesDropdown.setAttribute('placeholder', );
221. choicesDropdown.setAttribute('hint-text', 'Select singular option');
222.
223. selectedField.choices.forEach(choice => {
224. const option = document.createElement('fw-select-option');
225. option.setAttribute('value', choice.id);
226. option.textContent = choice.value;
227. choicesDropdown.appendChild(option);
228.
229. if (selectedChoices && selectedChoices.includes(String(choice.id))) {
230. option.setAttribute('selected', 'selected');
231. }
232. });
233.
234. // Append the choices dropdown to the container
235. choicesContainer.appendChild(choicesDropdown);
236.
237. // Listen for changes in the choices selection
238. choicesDropdown.addEventListener('fwChange', (event) => {
239. const selectedChoiceId = event.target.value;
240.
241. // Find the event condition for the selected event name
242. let eventCondition = ticketworkflowconditions.find(cond => cond.eventName === selectedEventValue);
243. if (!eventCondition) {
244. eventCondition = { eventName: selectedEventValue, isEnabled: true, fields: {} };
245. ticketworkflowconditions.push(eventCondition);
246. }
247.
248. // Update the fields object with the selected choice
249. if (!eventCondition.fields) {
250. eventCondition.fields = {};
251. }
252. eventCondition.fields[selectedFieldName] = selectedChoiceId;
253.
254. console.log();
255. });
256.
257. // Add a button to create additional fields and choices
258. const addButton = document.createElement('button');
259. addButton.textContent = 'Add New Field & Choices';
260. addButton.classList.add('btn', 'btn-primary', 'mt-3'); // Styling the button
261.
262. // Button event listener to add new fields and choices dropdowns
263. addButton.addEventListener('click', () => {
264. createAdditionalDropdowns(container);
265. });
266.
267. // Append the add button to the button container
268. buttonContainer.appendChild(addButton);
269. }
270.
271. function createAdditionalDropdowns(container) {
272. // Create new containers for field name, choices, and button
273. const fieldNameContainer = document.createElement('div');
274. fieldNameContainer.classList.add('col-md-2', 'field-name-container', 'offset-md-2');
275. const choicesContainer = document.createElement('div');
276. choicesContainer.classList.add('col-md-2', 'choices-container');
277. const buttonContainer = document.createElement('div');
278. buttonContainer.classList.add('col-md-3', 'button-container', 'mt-3');
279.
280. // Create delete button
281. const deleteButton = document.createElement('button');
282. deleteButton.textContent = 'Delete';
283. deleteButton.classList.add('btn', 'btn-danger', 'mt-2');
284. buttonContainer.appendChild(deleteButton);
285.
286. // Append new containers to the main container
287. container.appendChild(fieldNameContainer);
288. container.appendChild(choicesContainer);
289. container.appendChild(buttonContainer);
290.
291. // Call fieldschoosingvalues to populate new dropdowns
292. fieldschoosingvalues(
293. container.querySelector('.event-name-dropdown').value,
294. fieldNameContainer,
295. choicesContainer,
296. buttonContainer,
297. container
298. );
299.
300. // Add delete functionality
301. deleteButton.addEventListener('click', () => {
302. fieldNameContainer.remove();
303. choicesContainer.remove();
304. buttonContainer.remove();
305. });
306. }
Field and Choices Copying: When a new event is selected, it checks if there is an existing condition for the previously selected event. If it exists, it copies the fields from that existing event to the new event.
Preservation of State: The copying mechanism ensures that if you create events in succession, each new event can inherit the field configuration from the last selected event, simplifying the process of setting up multiple similar events.
Correct Workflow Condition Management: The array for workflowConditions is consistently managed by removing the old condition if it exists and adding the new one with the copied settings.
Usage
When you select an event, any fields associated with the previous event are preserved and copied over to the new event when you re-select it or select a new event.
You can easily add additional events while reusing existing configurations.
This approach keeps your code clean and flexible, allowing for easy expansions in the future.
console.log("Previous Selected Event:", selectedEvent); // Log the previous selected event
console.log("New Event Name:", newEvent);
const previousEventIndex = ticketworkflowconditions.findIndex(cond => cond.eventName === selectedEvent);
if (previousEventIndex !== -1) {
ticketworkflowconditions.splice(previousEventIndex, 1);
console.log(`Removed existing condition for event: "${selectedEvent}"`);
}
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new condition for the newly selected event
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
ticketworkflowconditions.push(newCondition);
console.log(`Added new condition for: "${newEvent}"`);
// Create new containers for fields and choices
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container');
newDropdownSet.appendChild(fieldNameContainer);
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
newDropdownSet.appendChild(choicesContainer);
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container');
buttonContainer.style.marginTop = '25px';
newDropdownSet.appendChild(buttonContainer);
// Populate fields based on the new event's context
await fieldschoosingvalues(newEvent, fieldNameContainer, choicesContainer, buttonContainer, newDropdownSet, null, null);
// Log the updated state of ticketworkflowconditions
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
// Update the selected event after the change
selectedEvent = newEvent; // Reassign selectedEvent here
});
// Append the newDropdownSet to the eventContainer
eventContainer.appendChild(newDropdownSet);
ticketworkflowContainer.appendChild(eventContainer);
}
async function fieldschoosingvalues(selectedEventValue, fieldNameContainer, choicesContainer, buttonContainer, container, selectedFieldName = null, selectedChoices = null) {
if (!selectedEventValue) {
console.error("fieldschoosingvalues called with an undefined selectedEventValue.");
return;
}
try {
let statusResp = await makeApiCall(apiKeyInput1.value, domainInput1.value);
// Select the current selected field if available
if (selectedFieldName && field.name === selectedFieldName) {
option.setAttribute('selected', 'selected');
}
});
fieldNameContainer.appendChild(fieldDropdown);
if (selectedFieldName) {
const selectedField = fields.find(field => field.name === selectedFieldName);
if (selectedField) {
await showingitschoices(choicesContainer, selectedField, selectedEventValue, selectedFieldName, buttonContainer, container, fieldNameContainer, selectedChoices);
} else {
console.error('Field not found in Dropdown');
}
}
// Find the event condition for the selected event name
const eventCondition = ticketworkflowconditions.find(cond => cond.eventName === selectedEventValue);
if (eventCondition) {
const previousFieldName = selectedFieldName; // Store the previous selected field name
// Log the previous field name for debugging
console.log(`Previous field name: ${previousFieldName}`);
if (previousFieldName && previousFieldName !== newSelectedFieldName) {
// Don't replace, just add new values
if (!eventCondition.fields) {
eventCondition.fields = {};
}
eventCondition.fields[newSelectedFieldName] = null; // Add the new field with a placeholder value (null)
console.log(`Added new field "${newSelectedFieldName}" to event condition.`);
}
// Clear the choices container before adding new choices
choicesContainer.innerHTML = '';
const newSelectedField = fields.find(field => field.name === newSelectedFieldName);
if (newSelectedField) {
await showingitschoices(choicesContainer, newSelectedField, selectedEventValue, newSelectedFieldName, buttonContainer, container, fieldNameContainer);
} else {
console.error('Field not found in Dropdown');
}
}
if (selectedChoices && selectedChoices.includes(String(choice.id))) {
option.setAttribute('selected', 'selected');
}
});
// Append the choices dropdown to the container
choicesContainer.appendChild(choicesDropdown);
// Listen for changes in the choices selection
choicesDropdown.addEventListener('fwChange', (event) => {
const selectedChoiceId = event.target.value;
code
// Find the event condition for the selected event name
let eventCondition = ticketworkflowconditions.find(cond => cond.eventName === selectedEventValue);
if (!eventCondition) {
eventCondition = { eventName: selectedEventValue, isEnabled: true, fields: {} };
ticketworkflowconditions.push(eventCondition);
}
// Update the fields object with the selected choice
if (!eventCondition.fields) {
eventCondition.fields = {};
}
eventCondition.fields[selectedFieldName] = selectedChoiceId;
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
});
// Add a button to create additional fields and choices
const addButton = document.createElement('button');
addButton.textContent = 'Add New Field & Choices';
addButton.classList.add('btn', 'btn-primary', 'mt-3'); // Styling the button
// Button event listener to add new fields and choices dropdowns
addButton.addEventListener('click', () => {
createAdditionalDropdowns(container);
});
// Append the add button to the button container
buttonContainer.appendChild(addButton);
}
// Function to create additional dropdowns dynamically
function createAdditionalDropdowns(container) {
// Create new containers for field name, choices, and button
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container', 'offset-md-2');
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container', 'mt-3');
// Append new containers to the main container
container.appendChild(fieldNameContainer);
container.appendChild(choicesContainer);
container.appendChild(buttonContainer);
// Call fieldschoosingvalues to populate new dropdowns
fieldschoosingvalues(
container.querySelector('.event-name-dropdown').value,
fieldNameContainer,
choicesContainer,
buttonContainer,
container
);
i choosed a event 'ticket create' and choosed fields and choices. now i add another event with same event value and choosed fields and choices, why it overwrites existing it should add as another one
async function addNewRule(eventName, workflowConditions) {
console.log("Existing Workflow Conditions:", workflowConditions);
const ticketworkflowContainer = document.getElementById('ticketworkflow-container');
const eventContainer = document.createElement('div');
eventContainer.classList.add('event-container');
eventContainer.style.boxShadow = '0 5px 10px 0 rgba(0, 0, 0, 0.2)';
eventContainer.style.padding = '30px';
eventContainer.style.marginBottom = '15px';
eventContainer.style.borderRadius = '5px';
eventContainer.style.backgroundColor = '#fff';
const newDropdownSet = document.createElement('div');
newDropdownSet.classList.add('row', 'ticketworkflow-dropdown');
let selectedEvent = typeof eventName === 'string' ? eventName : '';
newDropdownSet.innerHTML = `
<div class="col-md-2 event-name-container">
<fw-select
class="event-name-dropdown"
label="Select Event Name"
required="true"
placeholder="Your choice"
hint-text="Select singular option">
<fw-select-option value="TicketCreate" ${selectedEvent === "TicketCreate" ? "selected" : ""}>Ticket Create</fw-select-option>
<fw-select-option value="TicketUpdate" ${selectedEvent === "TicketUpdate" ? "selected" : ""}>Ticket Update</fw-select-option>
<fw-select-option value="TicketCreateandUpdate" ${selectedEvent === "TicketCreateandUpdate" ? "selected" : ""}>Ticket Create and Update</fw-select-option>
</fw-select>
</div>
`;
const eventSelect = newDropdownSet.querySelector('.event-name-dropdown');
eventSelect.addEventListener('fwChange', async () => {
const newEvent = eventSelect.value;
console.log("Selected Event:", newEvent);
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new condition, whether or not it already exists
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
workflowConditions.push(newCondition);
console.log(`Added new condition for: "${newEvent}"`);
// Create new containers for fields and choices
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container');
newDropdownSet.appendChild(fieldNameContainer);
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
newDropdownSet.appendChild(choicesContainer);
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container');
buttonContainer.style.marginTop = '25px';
newDropdownSet.appendChild(buttonContainer);
// Populate fields based on the new event's context
await fieldschoosingvalues(newEvent, fieldNameContainer, choicesContainer, buttonContainer, newDropdownSet, null, null);
// Log the updated state of ticketworkflowconditions
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(workflowConditions, null, 2)}`);
// Update the selected event after the change
selectedEvent = newEvent; // Reassign selectedEvent here
});
// Append the newDropdownSet to the eventContainer
eventContainer.appendChild(newDropdownSet);
ticketworkflowContainer.appendChild(eventContainer);
}
Key Changes Explained:
Remove Existing Condition Logic: The logic that removed the existing condition for the currently selected event (ticketworkflowconditions.splice(previousEventIndex, 1);) has been removed to prevent overwriting.
Always Add a New Condition: When a new event name is selected, a new condition is always added to workflowConditions.
Result
With these changes, if you select "Ticket Create" multiple times, each selection will create a new condition in workflowConditions instead of overwriting the existing one.
Notes
Remember to handle how duplicate event names are displayed or managed in your UI, as having multiple identical event conditions might create confusion for users. You may want to add unique identifiers or enforce limits on event name reuse as necessary for your application's logic.
async function addNewRule(eventName, workflowConditions) {
console.log("Existing Workflow Conditions:", workflowConditions);
const ticketworkflowContainer = document.getElementById('ticketworkflow-container');
const eventContainer = document.createElement('div');
eventContainer.classList.add('event-container');
eventContainer.style.boxShadow = '0 5px 10px 0 rgba(0, 0, 0, 0.2)';
eventContainer.style.padding = '30px';
eventContainer.style.marginBottom = '15px';
eventContainer.style.borderRadius = '5px';
eventContainer.style.backgroundColor = '#fff';
const newDropdownSet = document.createElement('div');
newDropdownSet.classList.add('row', 'ticketworkflow-dropdown');
let selectedEvent = typeof eventName === 'string' ? eventName : '';
newDropdownSet.innerHTML = `
<div class="col-md-2 event-name-container">
<fw-select
class="event-name-dropdown"
label="Select Event Name"
required="true"
placeholder="Your choice"
hint-text="Select singular option">
<fw-select-option value="TicketCreate" ${selectedEvent === "TicketCreate" ? "selected" : ""}>Ticket Create</fw-select-option>
<fw-select-option value="TicketUpdate" ${selectedEvent === "TicketUpdate" ? "selected" : ""}>Ticket Update</fw-select-option>
<fw-select-option value="TicketCreateandUpdate" ${selectedEvent === "TicketCreateandUpdate" ? "selected" : ""}>Ticket Create and Update</fw-select-option>
</fw-select>
</div>
`;
const eventSelect = newDropdownSet.querySelector('.event-name-dropdown');
eventSelect.addEventListener('fwChange', async () => {
const newEvent = eventSelect.value;
console.log("Selected Event:", newEvent);
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new condition for the selected event name
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
workflowConditions.push(newCondition);
console.log(`Added new condition for: "${newEvent}"`);
// Create new containers for fields and choices
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container');
newDropdownSet.appendChild(fieldNameContainer);
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
newDropdownSet.appendChild(choicesContainer);
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container');
buttonContainer.style.marginTop = '25px';
newDropdownSet.appendChild(buttonContainer);
// Populate fields based on the new event's context
await fieldschoosingvalues(newEvent, fieldNameContainer, choicesContainer, buttonContainer, newDropdownSet, null, null);
// Log the updated state of workflowConditions
console.log(`Updated workflowConditions: ${JSON.stringify(workflowConditions, null, 2)}`);
});
// Append the newDropdownSet to the eventContainer
eventContainer.appendChild(newDropdownSet);
ticketworkflowContainer.appendChild(eventContainer);
}
// Modify getFieldnamesfrom1stapi to handle fields uniquely for each event instance
async function getFieldnamesfrom1stapi(fieldNameContainer, fields, choicesContainer, selectedEventValue, buttonContainer, container, selectedFieldName = null, selectedChoices = null) {
if (!selectedEventValue) {
console.error("Select an event before proceeding.");
return;
}
const fieldDropdown = document.createElement('fw-select');
fieldDropdown.classList.add('field-name-dropdown');
fieldDropdown.setAttribute('label', 'Ticket Fields');
fieldDropdown.setAttribute('required', 'true');
fieldDropdown.setAttribute('placeholder', 'Choose a field');
fieldDropdown.setAttribute('hint-text', 'Select singular option');
fields.forEach(field => {
const option = document.createElement('fw-select-option');
option.setAttribute('value', field.name);
option.textContent = field.label;
fieldDropdown.appendChild(option);
});
fieldNameContainer.appendChild(fieldDropdown);
fieldDropdown.addEventListener('fwChange', async (event) => {
const newSelectedFieldName = event.target.value;
const eventCondition = workflowConditions.find(cond => cond.eventName === selectedEventValue);
if (eventCondition) {
eventCondition.fields[newSelectedFieldName] = null; // Add the new field with a placeholder value
console.log(`Added new field "${newSelectedFieldName}" to event condition for "${selectedEventValue}".`);
// Clear the choices container before adding new choices
choicesContainer.innerHTML = '';
const selectedField = fields.find(field => field.name === newSelectedFieldName);
if (selectedField) {
await showingitschoices(choicesContainer, selectedField, selectedEventValue, newSelectedFieldName, buttonContainer, container, fieldNameContainer);
} else {
console.error('Field not found in Dropdown');
}
}
});
}
Key Points in the Code:
Maintaining Independent Fields: Each time you select an event, a new condition is created for that event, and fields and choices are stored under that condition. Each condition holds its own fields map.
Adding Fields: Whenever a new field is selected, it is added to the corresponding event condition's fields object. This means if you select the same event multiple times, each selection still maintains its own set of choices.
Choices Management: The choices for a field are set up within the scope of that particular event condition, avoiding any clash between fields of different conditions.
By keeping the structure of the event conditions modular and encapsulated, you can guarantee that each event can track its fields and choices independently, fulfilling your requirement perfectly.
Example Scenario
First Condition: Select "Ticket Create", choose "Priority" with choices for "High", and save.
Second Condition: Select "Ticket Create" again, choose "Status" with choices for "Open", and save independently of the first condition.
Now you can have multiple conditions with the same event name while retaining unique values for their respective fields and choices.
async function addNewRule(eventName, workflowConditions) {
console.log("Existing Workflow Conditions:", workflowConditions);
const ticketworkflowContainer = document.getElementById('ticketworkflow-container');
const eventContainer = document.createElement('div');
eventContainer.classList.add('event-container');
eventContainer.style.boxShadow = '0 5px 10px 0 rgba(0, 0, 0, 0.2)';
eventContainer.style.padding = '30px';
eventContainer.style.marginBottom = '15px';
eventContainer.style.borderRadius = '5px';
eventContainer.style.backgroundColor = '#fff';
const newDropdownSet = document.createElement('div');
newDropdownSet.classList.add('row', 'ticketworkflow-dropdown');
// Use 'let' to allow reassignment of selectedEvent
let selectedEvent = typeof eventName === 'string' ? eventName : '';
newDropdownSet.innerHTML = `
<div class="col-md-2 event-name-container">
<fw-select
class="event-name-dropdown"
label="Select Event Name"
required="true"
placeholder="Your choice"
hint-text="Select singular option">
<fw-select-option value="TicketCreate" ${selectedEvent === "TicketCreate" ? "selected" : ""}>Ticket Create</fw-select-option>
<fw-select-option value="TicketUpdate" ${selectedEvent === "TicketUpdate" ? "selected" : ""}>Ticket Update</fw-select-option>
<fw-select-option value="TicketCreateandUpdate" ${selectedEvent === "TicketCreateandUpdate" ? "selected" : ""}>Ticket Create and Update</fw-select-option>
</fw-select>
</div>
`;
const eventSelect = newDropdownSet.querySelector('.event-name-dropdown');
// When the event changes, create a separate condition
eventSelect.addEventListener('fwChange', async () => {
const newEvent = eventSelect.value;
console.log("Selected Event:", newEvent);
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new independent condition for the selected event
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
workflowConditions.push(newCondition);
console.log(`Added new condition for: "${newEvent}"`);
// Create new containers for fields and choices
const fieldNameContainer = document.createElement('div');
fieldNameContainer.classList.add('col-md-2', 'field-name-container');
newDropdownSet.appendChild(fieldNameContainer);
const choicesContainer = document.createElement('div');
choicesContainer.classList.add('col-md-2', 'choices-container');
newDropdownSet.appendChild(choicesContainer);
const buttonContainer = document.createElement('div');
buttonContainer.classList.add('col-md-3', 'button-container');
buttonContainer.style.marginTop = '25px';
newDropdownSet.appendChild(buttonContainer);
// Call to populate fields based on the new event's context
await fieldschoosingvalues(newEvent, fieldNameContainer, choicesContainer, buttonContainer, newDropdownSet, null, null);
// Log the updated state of workflowConditions
console.log(`Updated workflowConditions: ${JSON.stringify(workflowConditions, null, 2)}`);
});
// Append the newDropdownSet to the eventContainer
eventContainer.appendChild(newDropdownSet);
ticketworkflowContainer.appendChild(eventContainer);
}
// Modify the field selection logic to handle fields independently
async function getFieldnamesfrom1stapi(fieldNameContainer, fields, choicesContainer, selectedEventValue, buttonContainer, container, selectedFieldName = null, selectedChoices = null) {
if (!selectedEventValue) {
console.error("Select an event before proceeding.");
return;
}
const fieldDropdown = document.createElement('fw-select');
fieldDropdown.classList.add('field-name-dropdown');
fieldDropdown.setAttribute('label', 'Ticket Fields');
fieldDropdown.setAttribute('required', 'true');
fieldDropdown.setAttribute('placeholder', 'Choose a field');
fieldDropdown.setAttribute('hint-text', 'Select singular option');
fields.forEach(field => {
const option = document.createElement('fw-select-option');
option.setAttribute('value', field.name);
option.textContent = field.label;
fieldDropdown.appendChild(option);
});
fieldNameContainer.appendChild(fieldDropdown);
fieldDropdown.addEventListener('fwChange', async (event) => {
const newSelectedFieldName = event.target.value;
const eventCondition = workflowConditions.find(cond => cond.eventName === selectedEventValue);
if (eventCondition) {
// Update the event condition's fields without overwriting others
eventCondition.fields[newSelectedFieldName] = ''; // Prepare to store the choice value
console.log(`Added new field "${newSelectedFieldName}" to event condition "${selectedEventValue}".`);
// Clear the choices container before adding new choices
choicesContainer.innerHTML = '';
const selectedField = fields.find(field => field.name === newSelectedFieldName);
if (selectedField) {
await showingitschoices(choicesContainer, selectedField, selectedEventValue, newSelectedFieldName, buttonContainer, container, fieldNameContainer);
} else {
console.error('Field not found in Dropdown');
}
}
});
}
// Ensure each condition manages its own choices independently
async function showingitschoices(choicesContainer, selectedField, selectedEventValue, selectedFieldName, buttonContainer, container, fieldNameContainer, selectedChoices = null) {
choicesContainer.innerHTML = ''; // Clear existing choices
const choicesDropdown = document.createElement('fw-select');
choicesDropdown.classList.add('choices-dropdown');
choicesDropdown.setAttribute('label', `${selectedFieldName}`);
choicesDropdown.setAttribute('required', 'true');
choicesDropdown.setAttribute('placeholder', `Choose ${selectedFieldName}`);
choicesDropdown.setAttribute('hint-text', 'Select singular option');
selectedField.choices.forEach(choice => {
const option = document.createElement('fw-select-option');
option.setAttribute('value', choice.id);
option.textContent = choice.value;
choicesDropdown.appendChild(option);
});
choicesContainer.appendChild(choicesDropdown);
choicesDropdown.addEventListener('fwChange', (event) => {
const selectedChoiceId = event.target.value;
const eventCondition = workflowConditions.find(cond => cond.eventName === selectedEventValue);
if (eventCondition) {
// Store the selected choice in the respective field
eventCondition.fields[selectedFieldName] = selectedChoiceId; // Store choice value for this specific field and event condition
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(workflowConditions, null, 2)}`);
}
});
}
Key Changes in This Implementation:
Independent Conditions: Each event selection creates a new condition in the workflowConditions that is independent of prior conditions, even if they have the same eventName.
Field and Choice Management: When a field is chosen and a choice is made, the corresponding value is stored directly in the fields object of that specific event condition. Thus, fields like group and priority can coexist independently without overlapping or overwriting each other’s values.
Logging: The logging statements help trace what happens step by step for better debugging and understanding of data changes.
Final Behavior
If you first set group to 5 for the first condition of "TicketCreate" and later choose the same event to set the priority, that choice will not affect the first condition. Each condition’s fields are strictly separated, allowing for easy and clear management of multiple conditions with the same event name.
This should meet your requirement of managing configurations independently without conflicts. Let me know if you need further adjustments or clarifications!
4. Use Debugging
When debugging this sort of issue, it's often useful to log out the variable right before you attempt to manipulate it:
Here’s an updated version of the relevant parts of addNewRule() ensuring that workflowConditions is checked appropriately:
javascript
async function addNewRule(eventName, workflowConditions) {
console.log("Existing Workflow Conditions:", workflowConditions);
// Ensure workflowConditions is an array
if (!Array.isArray(workflowConditions)) {
console.error("workflowConditions is not an array. Initializing as empty array.");
workflowConditions = [];
}
const ticketworkflowContainer = document.getElementById('ticketworkflow-container');
const eventContainer = document.createElement('div');
eventContainer.classList.add('event-container');
eventContainer.style.boxShadow = '0 5px 10px 0 rgba(0, 0, 0, 0.2)';
eventContainer.style.padding = '30px';
eventContainer.style.marginBottom = '15px';
eventContainer.style.borderRadius = '5px';
eventContainer.style.backgroundColor = '#fff';
const newDropdownSet = document.createElement('div');
newDropdownSet.classList.add('row', 'ticketworkflow-dropdown');
let selectedEvent = typeof eventName === 'string' ? eventName : '';
newDropdownSet.innerHTML = `
<div class="col-md-2 event-name-container">
<fw-select
class="event-name-dropdown"
label="Select Event Name"
required="true"
placeholder="Your choice"
hint-text="Select singular option">
<fw-select-option value="TicketCreate" ${selectedEvent === "TicketCreate" ? "selected" : ""}>Ticket Create</fw-select-option>
<fw-select-option value="TicketUpdate" ${selectedEvent === "TicketUpdate" ? "selected" : ""}>Ticket Update</fw-select-option>
<fw-select-option value="TicketCreateandUpdate" ${selectedEvent === "TicketCreateandUpdate" ? "selected" : ""}>Ticket Create and Update</fw-select-option>
</fw-select>
</div>
`;
const eventSelect = newDropdownSet.querySelector('.event-name-dropdown');
eventSelect.addEventListener('fwChange', async () => {
const newEvent = eventSelect.value;
// Ensure workflowConditions is valid before pushing
if (!Array.isArray(workflowConditions)) {
console.error("workflowConditions is not an array.");
return;
}
console.log("Selected Event:", newEvent);
// Clear existing field-related containers
newDropdownSet.querySelectorAll('.field-name-container, .choices-container, .button-container').forEach(container => container.remove());
// Create a new independent condition for the selected event
const newCondition = { eventName: newEvent, isEnabled: true, fields: {} };
workflowConditions.push(newCondition);
console.log(`Added new condition for: "${newEvent}"`);
// Additional logic for fields and choices will go here...
});
// Append the newDropdownSet to the eventContainer
eventContainer.appendChild(newDropdownSet);
ticketworkflowContainer.appendChild(eventContainer);
}
Conclusion
By ensuring that your workflowConditions variable is always properly initialized and handled as an array, you should be able to eliminate the TypeError related to uninitialized or undefined variables.
If the issue persists, please correspondingly check where addNewRule function is invoked, and make sure you're passing a valid array for workflowConditions.
Removed existing condition for event: "${selectedEvent}"