Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Populate cc field based on dropdown list values

Avatar

Level 2

I know this question has been posted before, but I'm very new at this, and the answers I've found so far are over my head.

I'm trying to create a submit button that will not only e-mail to a specific address, but also carbon copy someone when their name is selected in a drop-down list on the form.

I don't know much about javascript - and that seems to be the way to get this done - but I don't know the syntax or where to enter the JS to get this functionality. The field I am using is called 'Supervisor1', and I've assigned values (e-mail addresses) to each of the names in the drop-down.

Can someone help me get this done?

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

if you are a scripting newbie, you might think this macro useful.

It can add a mail script to a regular button.

http://thelivecycle.blogspot.de/2012/05/mailto-maker-marco-v1.html

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

Hi,

if you are a scripting newbie, you might think this macro useful.

It can add a mail script to a regular button.

http://thelivecycle.blogspot.de/2012/05/mailto-maker-marco-v1.html

Avatar

Level 2

Thank you for your response... When I try to enter this, it highlights the row with the click event in red... And in the list of events, when I click mouseDown, it has the click event included with it, not as its own.

What am I doing wrong? 

Edit: I got the click event to show in the script editor, by changing the button control type to 'regular'... I added the JS, but now the button does nothing when clicked. Again, I ask: what am I doing wrong here?

Edit2: Nevermind, your answer works perfectly... I was just referencing the wrong place in the hierarchy for where the drop-down list sits.

Thanks for your help!

Avatar

Level 2

Okay, new problem... Now that I've got this working, the e-mail is cc'ed to the supervisors when a name is selected from the drop-down... But when it's left blank, MS Outlook searches, literally, for "Null" in the address book, and copies the first Null it finds on the e-mail/form submission.

Due to certain requirements, I can't make either/both of the supervisor fields mandatory, but I'd like to generate a pop-up/error of some sort when one/both of these fields are left blank.

Can anyone help with this?

Avatar

Level 10

Hi,

this scenario is not covered by the macro, but it's not that complicated to handle.

1. Select the button with the script you generated with the macro.

2. Now wrap the mail function into an if-expression.

This sample checks if var0 or var1 is null.

var var0 = xfa.resolveNode("Formular1.#subform.Dropdown1").rawValue;

var var1 = xfa.resolveNode("Formular1.#subform.Textfield1").rawValue;

if (var0 === null || var1 === null) {

          xfa.host.messageBox("Please select an item from the drop down box first!");

} else {

          event.target.mailDoc({

                    bUI: false,

                    cTo: var1,

                    cCc: var0,

                    cBcc: '',

                    cSubject: 'Testmail',

                    cMsg: 'Hello,\n\nhere is the final form data. \n\nKind regards\nMe'

          });

}

Avatar

Level 2

You are a lifesaver Thanks again

Avatar

Level 2

What would the syntax be for a nested if statement? I'm wanting to add a condition that another (different) message pop up if a separate field is left blank instead of (or in addition to) these two fields.

Avatar

Level 10

Hi,

it could look like if there is for example a check box checked or unchecked.

var var0 =

xfa.resolveNode("form1.#subform.CheckBox1").rawValue === "1" ? xfa.resolveNode("form1.#subform.Dropdown1").rawValue : "";

var var1 = xfa.resolveNode("form1.#subform.Textfield1").rawValue;


if (var0 === null || var1 === null) {

           xfa.host.messageBox("Please select an item from the drop down box first!");

} else {

     event.target.mailDoc({                    

          bUI: false,

          cTo: var1,

          cCc: var0,

          cBcc: ''

                           cSubject: 'Testmail',

          cMsg: 'Hello,\n\nhere is the final form data. \n\nKind regards\nMe'

     });

}