Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

lostfrogg
Level 3
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
Kosta_Prokopiu1
Employee
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

lostfrogg
Level 3
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

Kosta_Prokopiu1
Employee
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.

lostfrogg
Level 3
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. 

 

Kosta_Prokopiu1
Employee
Employee

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

lostfrogg
Level 3
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

 

lostfrogg
Level 3
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

Kosta_Prokopiu1
Employee
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;

 

lostfrogg
Level 3
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?

lostfrogg
Level 3
Level 3

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

Kosta_Prokopiu1
Employee
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();

lostfrogg
Level 3
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;

Kosta_Prokopiu1
Employee
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;

lostfrogg
Level 3
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?

Kosta_Prokopiu1
Employee
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

lostfrogg
Level 3
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;

Kosta_Prokopiu1
Employee
Employee

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

lostfrogg
Level 3
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!

lostfrogg
Level 3
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!