Expand my Community achievements bar.

Looking to lock form on email submission and set something from the form in the email subject

Avatar

Level 3

I have added an email submission button. I've looked around but can't seem to find the answer to this - how do I lock the form on submission? The form has an auto-populate today's date box, and currently every time I open the form it resets it to the current date. 

Second, I have fields on the form for "forename" and "surname". Would it be possible to have the following in the "email subject": 

[specific text] - (forename initial) (surname initial)

 

Thanks!

61 Replies

Avatar

Employee

Since you packed 2 questions into 1 I answer the second one first.

Define your Submit by Email button WITHOUT the Email Subject: field.

 

Capture.PNGCapture.PNG

Then go to the preSubmit event of the Email button and place the following script there

var sMailUrl=this.resolveNode("#event").submit.target;
this.resolveNode("#event").submit.target=sMailUrl + "?subject=Some Text "+Forname.rawValue+" "+Surename.rawValue;

 

Capture.PNG

 

Capture.PNG

Avatar

Level 3

Many thanks for your answer. Is it possible to have it show the name initials in the subject line? So instead of "Kosta Prokopiu", it would show "KP"?

 

Also, I presume that I have to put in the "long" paths to the forename and surname fields in the script?

 

Thanks

Avatar

Employee

this.resolveNode("#event").submit.target=sMailUrl + "?subject=Some Text "+Forname.rawValue+" "+Surename.rawValue + "(" + Forname.rawValue.substr(0,1) + Surename.rawValue.substr(0,1) + ")";

adds your initials like Some Text Kosta Prokopiu(KP)

Paths depend on where the objects are. With me they are in the same level - in your case you may require the full path.

Avatar

Level 3

Hi Kosta, I have the following script in the "presubmit" area, running as Javascript;

var sMailUrl=this.resolveNode("#event").submit.target;
this.resolveNode("#event").submit.target=sMailUrl + "?subject=Referral to Liaison Psychiatry: "+form1.Page1subform.PatientSubform.Forname.rawValue+" "+form1.Page1subform.PatientSubform.Surename.rawValue;

When I submit the form however, the email title is still generic and does not incorporate the text or fields above. Any further help much appreciated. 

 

Avatar

Employee

I think that is the colon change it to Psychiatry\: then it should work.

Avatar

Level 3

Thanks Kosta. I changed the script as you suggested, so it now reads (under presubmit, JavaScript):

var sMailUrl=this.resolveNode("#event").submit.target;
this.resolveNode("#event").submit.target=sMailUrl + "?subject=Referral to Liaison Psychiatry\: "+form1.Page1subform.PatientSubform.Forname.rawValue+" "+form1.Page1subform.PatientSubform.Surename.rawValue;

But when I submit the form and it attaches to an email, this is what I see in the subject line:

email.jpg

 

Avatar

Level 3

Hi Kosta,

When I change the colon, so that the script under the preSubmit (JavaScript) window looks like this:

var sMailUrl=this.resolveNode("#event").submit.target;
this.resolveNode("#event").submit.target=sMailUrl + "?subject=Referral to Liaison Psychiatry\: "+form1.Page1subform.PatientSubform.Forname.rawValue+" "+form1.Page1subform.PatientSubform.Surename.rawValue;

I get a standard email subject line like this:

email.jpg

Avatar

Employee

Somehow your last question disappeared. I get the same when I switch from XML submit to PDF submit. I solved it by changing the Submit button as follows:

Kosta_Prokopiu1_0-1603986159792.png

Then I change the preSubmit script as follows (make sure that you replace the subject tag as defined above ("x"):

var sMailUrl=this.resolveNode("#event").submit.target;
sMailUrl = sMailUrl.substr(0,sMailUrl.indexOf("?subject=x")) + "?subject=Some Text\: " + Forname.rawValue + " " + Surename.rawValue + " (" + Forname.rawValue.substr(0,1) + Surename.rawValue.substr(0,1) + ")";
//contains the mailto: with the e-mail address
this.resolveNode("#event").submit.target=sMailUrl;

 

Avatar

Level 3

Hi Kosta,

Yes that seemed to fix the issue! Thank you. One thing - with your script, I get this in the email subject header:

Some Text: sdf sdf (ss)

But what I am trying to get is:

Some Text: SS

I've been trying to delete the sdf bits but have been struggling to get it to work. Also not sure how to make the initials appear in capitals?

Avatar

Level 3

Hi Kosta, not sure if you received my last message about having just the initials in capitals?

Avatar

Employee

I am off from time to time and the League is not my day job ....

I can see that scripting is not your strongest side. Change the line

 

this.resolveNode("#event").submit.target=sMailUrl + "?subject=Some Text "+Forname.rawValue+" "+Surename.rawValue + "(" + Forname.rawValue.substr(0,1) + Surename.rawValue.substr(0,1) + ")";

to

this.resolveNode("#event").submit.target=sMailUrl + "?subject=Some Text "+ Forname.rawValue.substr(0,1).toUpperCase() + Surename.rawValue.substr(0,1).toUpperCase();

Avatar

Level 3

Thanks Kosta, I do appreciate all your input!

You mention to change that line - but that line doesn't appear in the script you gave me:

var sMailUrl=this.resolveNode("#event").submit.target;
sMailUrl = sMailUrl.substr(0,sMailUrl.indexOf("?subject=x")) + "?subject=Some Text\: " + Forname.rawValue + " " + Surename.rawValue + " (" + Forname.rawValue.substr(0,1) + Surename.rawValue.substr(0,1) + ")";
//contains the mailto: with the e-mail address
this.resolveNode("#event").submit.target=sMailUrl;

Avatar

Employee

var sMailUrl=this.resolveNode("#event").submit.target;
sMailUrl = sMailUrl.substr(0,sMailUrl.indexOf("?subject=x")) + "?subject=Some Text\: " +  + Forname.rawValue.substr(0,1).toUpperCase() + Surename.rawValue.substr(0,1).toUpperCase();
//contains the mailto: with the e-mail address
this.resolveNode("#event").submit.target=sMailUrl;

Avatar

Level 3

Thanks again Kosta - but with that code (I changed the "some text"), if the Forename is wqdwqd and the surname is qwd, I get the following in the email subject line: 

Screenshot 2020-11-10 211839.jpg

I would expect to get the intials WQ, not NaNQ!

Any idea what's going wrong?

Avatar

Employee

@lostfroggYou must have an error on the script line - NaN means Not a Number - it seems to interpret something as a number and fails, your second name seems to be ok, Post me that line in your code to have a look

Avatar

Level 3

@Kosta_Prokopiu1  here is the code - it's basically the one you have just given me, but with the long paths for the field names:

var sMailUrl=this.resolveNode("#event").submit.target;
sMailUrl = sMailUrl.substr(0,sMailUrl.indexOf("?subject=x")) + "?subject=Liaison psychiatry referral\: " + + form1.Page1subform.PatientSubform.Forename.rawValue.substr(0,1).toUpperCase() + form1.Page1subform.PatientSubform.Surname.rawValue.substr(0,1).toUpperCase();
//contains the mailto: with the e-mail address
this.resolveNode("#event").submit.target=sMailUrl;

Avatar

Employee

replace referral\:" + + with \:" +  the additional + sign causes the issue I think.

Avatar

Level 3

Yes, that did it! Thank you. Now I just need to wait until tomorrow to check that the "current date" field locks on form submission, and I'll be finished!

Avatar

Level 3

Hi Kosta,

One final query, if you would be so kind. The "current date" field is still not locking - I checked this morning and when I opened the form in Acrobat Reader, it updated the "current date" field to today's date.

This is what I have in the "current date" field when I go to "events with scripts":

form1.Page1subform.Datenamegradesubform.DateField1::initialize - (FormCalc, client)

$=Num2Date(date(),"YYYY-MM-DD")

form1.Page1subform.Datenamegradesubform.DateField1::ready:layout - (FormCalc, client)

if ($ == null) then
$.rawValue = Num2Date(date(),"YYYY-MM-DD")
endif

The language for the field is set to FormCalc. 

In the Object properties for the field, I have the following:

Type: Date/Time Field

Locale: Default locate - English (USA)

If I click on "patterns", then all the boxes are empty. 

In the "value" tab for the field, the "type" is set to "Calculated - Read Only", with "calculation script" selected. 

If I go to "file" then "form properties" then "defaults", the "Form Locale" is set to "English (USA)".

Any help with this much appreciated!