Expand my Community achievements bar.

SOLVED

Create Email Subject from Text Field

Avatar

Level 1

Is it possible to generate the email subject from a user-filled text field?

For example:

When the user enters 'John Doe' for their name in a form, the subject line would be 'John Doe'.

 

<submit format="pdf" textEncoding="UTF-8" target="mailto:mbox@company.com?subject=<John Doe>"/>

1 Accepted Solution

Avatar

Correct answer by
Level 1

Made some minor changes to your script to get what I needed:

var myDoc = event.target;

var address = "myemail@contoso.com, secondemail@contoso.com";

var subject = [TargetFieldName1.rawValue, TargetFieldName2.rawValue, " Additional Static Text"];

subject.toString();

myDoc.mailDoc({

bEmpty: true,

cTo: address,

cSubject: subject,

csubmîtAs: "PDF"

});

Also, I found out I needed a normal button that calls this script when clicked.  Otherwise, thank you for getting me pointed in the right direction.

View solution in original post

8 Replies

Avatar

Level 10

Another method is using my  macro (usable in Designer ES2 or higher).

You can create a complete mail (recipients, subject and message) and add variables from fields to all of them.

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

http://4.bp.blogspot.com/-THPsjHSlpjo/T8UbTb5LX7I/AAAAAAAAAfU/KUu2jELkOEc/s320/Step_4.png

Avatar

Level 2

Use can use this script for getting subject from textfield

var myDoc = event.target;

var address = "";

var subject = TextField.rawValue,

myDoc.mailDoc({

bEmpty: true,

cTo: address,

cSubject: subject,

csubmîtAs: "PDF"

});

Avatar

Level 1

You'll have to forgive my ignorance, but I don't understand much about scripting.  Right now, I'm using the 'Email Submit Button' and don't know where to put the suggestions above.  Could someone provide an example please?

Avatar

Correct answer by
Level 1

Made some minor changes to your script to get what I needed:

var myDoc = event.target;

var address = "myemail@contoso.com, secondemail@contoso.com";

var subject = [TargetFieldName1.rawValue, TargetFieldName2.rawValue, " Additional Static Text"];

subject.toString();

myDoc.mailDoc({

bEmpty: true,

cTo: address,

cSubject: subject,

csubmîtAs: "PDF"

});

Also, I found out I needed a normal button that calls this script when clicked.  Otherwise, thank you for getting me pointed in the right direction.

Avatar

Level 1

I can't seem to get this to fire when in the "click" event of my button.  Am I missing any essential bits?

Avatar

Level 1

I'm in the same boat as G5_Matty.
I've used the same coding, just adding in my data to suit, but I can't seem to get the button to work?

It's not telling me I have any coding errors either.

Avatar

Level 10

Hi,

This code needs to be in a standard button, but it also has a few problems.

  • The email addresses should be separated with a semi-colon, not a comma
  • The line subject.toString(); doesn't do anything
  • The csubmîtAs has a special "i" character.
  • If you don't want a comma used between the fields in the subject you should use the .join(" ") to use spaces instead

Try this code

var myDoc = event.target;

var address = "myemail@contoso.com; secondemail@contoso.com";

var subject = [TargetFieldName1.rawValue, TargetFieldName2.rawValue, " Additional Static Text"];

myDoc.mailDoc({

bEmpty : true,

cTo : address,

cSubject : subject.join(" "),

csubmitAs : "PDF"

});

Regards

Bruce