I will start off by saying that this is NOT a question - this is purely informational. I hope this helps someone that experiences issues with pulling out array data from multi-select lists.
Brief:
I started off by creating a multi-select list control for displaying all employees within the organization. The idea behind this was obviously to allow employees to be managed by an HR department within the application itself. Of course, I included some basic features like creating new employees, editing existing employees and so on..
Skipping ahead a week, I was informed by my client that the HR department needed to be able to send out notifications via email, whether individually or in bulk. So I thought, "well, I have this HR module thing.. why not include it there?"..
Moving on.. I got everything set up the way I wanted and got to the point where it was time to actually focus on the notifications. I knew there were a lot of different ways I could do this, but for simplicity sake, I thought "it would probably be cool to allow HR to just select the employees they want to notify in the list, click a button, draft the email and send" (e.g. not having to input email addresses for every person they wanted to send the same notification to). The problem I had was getting the email addresses from the rows that were selected in the list. Having worked with list controls in the past, I knew about the selectionData array and how to access it. However, when I started actually writing the javascript, I could not for the life of me figure out how to pull only the email addresses from the selected rows in the array. Needless to say, I fiddled with this for almost an entire day in console. Initially, I was getting undefined errors left and right, then I finally got something promising in the form of [Object Object] while I was running in console which told me I was on the right track (for some odd reason, as I was getting the message a number of times depending on how many rows I had selected which told me that I was accessing the objects in the array).
Eventually, I was able to pull what I needed from the array and get it working via (in list's OnSelect event):
If there was a better and more efficient way to do this - please feel free to enlighten me.. I feel like I ran around this multiple times trying a million different things to get this working. But again, hopefully this will help someone out somewhere down the line..
Brief:
I started off by creating a multi-select list control for displaying all employees within the organization. The idea behind this was obviously to allow employees to be managed by an HR department within the application itself. Of course, I included some basic features like creating new employees, editing existing employees and so on..
Skipping ahead a week, I was informed by my client that the HR department needed to be able to send out notifications via email, whether individually or in bulk. So I thought, "well, I have this HR module thing.. why not include it there?"..
Moving on.. I got everything set up the way I wanted and got to the point where it was time to actually focus on the notifications. I knew there were a lot of different ways I could do this, but for simplicity sake, I thought "it would probably be cool to allow HR to just select the employees they want to notify in the list, click a button, draft the email and send" (e.g. not having to input email addresses for every person they wanted to send the same notification to). The problem I had was getting the email addresses from the rows that were selected in the list. Having worked with list controls in the past, I knew about the selectionData array and how to access it. However, when I started actually writing the javascript, I could not for the life of me figure out how to pull only the email addresses from the selected rows in the array. Needless to say, I fiddled with this for almost an entire day in console. Initially, I was getting undefined errors left and right, then I finally got something promising in the form of [Object Object] while I was running in console which told me I was on the right track (for some odd reason, as I was getting the message a number of times depending on how many rows I had selected which told me that I was accessing the objects in the array).
Eventually, I was able to pull what I needed from the array and get it working via (in list's OnSelect event):
Code:
if (this.initialized){ var lObj = {dialog.object}.getControl('list1'); //targeting list control var selectData = lObj.selectionData; //grabbing selected list data var lstArray = []; for(i=0;i<selectData.length;i++){ var newArray = []; newArray = lstArray.push(selectData[i].listColumn); } var myArray = [].concat(lstArray); //Created fresh array and put lstArray data in var joinedArray = myArray.join(','); //Separating email addresses w/ comma for multiple recipients {dialog.object}.setValue('textfield',joinedArray); //My email recipient field where selected employee's email addresses are output to }
If there was a better and more efficient way to do this - please feel free to enlighten me.. I feel like I ran around this multiple times trying a million different things to get this working. But again, hopefully this will help someone out somewhere down the line..
Comment