- This topic has 10 replies, 2 voices, and was last updated 6 months, 1 week ago by Alexander Bautz.
-
AuthorPosts
-
-
June 11, 2024 at 16:15 #37777
Hi, I am trying to achieve the below functionality –
-user clicks a button
– a multiline textbox opens for user input
– user clicks OK
– sent email is sent with user’s input in the emailHere’s the code that I call within button click but the textbox is not showing.
var varFromAlertInput = “”;
spjs.dffs.alert({
“title”: “Enter a return reason”,
“msg”: “<input id=’varFromAlertInput_input’ type=’text’>”,
“ok”: function(){
// Update the variable before closing
varFromAlertInput = jQuery(“#varFromAlertInput_input”).val();
}
});htmlBody.push(varFromAlertInput);
-
June 11, 2024 at 17:34 #37778
Try it like this:
spjs.dffs.alert({ "title": "Enter a return reason", "msg": "<textarea style='width:100%;box-sizing:border-box;height;75px;' id='varFromAlertInput_input'></textarea>", "ok": function(){ var fromAlertInput = jQuery("#varFromAlertInput_input").val(); spjs.dffs.REST_Email({ "to": ["user@sdomain.com"], "cc": [], "bcc": [], "subject": "This is a test email", "body": "This is the message: " + fromAlertInput }); }, "cancel": function(){ // Close dialog } });
Please note that this uses the built in SharePoint REST API to send the message and the recipient(s) must be members of the site.
Alexander
- This reply was modified 6 months, 1 week ago by Alexander Bautz. Reason: Fixed missing double quote
-
June 11, 2024 at 18:24 #37779
getting an error for this line
msg”: <textarea style=’width:100%;box-sizing:border-box;height;75px;’ id=’varFromAlertInput_input’></textarea>
VM12250:1 Uncaught SyntaxError: Invalid or unexpected token
-
June 11, 2024 at 19:19 #37780
Also, is it ok to separate out the email call from the alert? The reason I am asking is, because email needs to be fired each time with different info based on various scenarios.
call alert code from function1
spjs.dffs.alert({
“title”: “Enter a return reason”,
//”msg”: <textarea> style=’width:100%;box-sizing:border-box;height;75px;’ id=’varFromAlertInput_input’></textarea>”,
“msg”: “<input id=’varFromAlertInput_input’ type=’text’>”,
“ok”: function(){
var fromAlertInput = jQuery(“#varFromAlertInput_input”).val();
htmlBody.push(fromAlertInput);
},
“cancel”: function(){
// Close dialog
}
});then call the REST_EMail from function2?
spjs.dffs.REST_Email({
“to”: “” + jsEmailTo,
“cc”: [],
“bcc”: [],
“subject”:””+ sbj,
“body”:”” + jsEmailBody + fromAlertInput
}); -
June 11, 2024 at 22:02 #37782
I fixed a missing quote in the code snippet above. You can wrap it in a function something like this to use it from different other functions:
function sendCustomEmail(arg){ spjs.dffs.alert({ "title": "Enter a return reason", "msg": "<textarea style='width:100%;box-sizing:border-box;height;75px;' id='varFromAlertInput_input'></textarea>", "ok": function(){ var fromAlertInput = jQuery("#varFromAlertInput_input").val(); spjs.dffs.REST_Email({ "to": arg.to, "cc": arg.cc, "bcc": arg.bcc, "subject": arg.subject, "body": arg.body.split("{0}").join(fromAlertInput) }); }, "cancel": function(){ // Close dialog } }); } // Call the function like this sendCustomEmail({ "to": ["alexander@spjsblog.com"], "cc": [], "bcc": [], "subject": "The subject of the email", "body": "The default body - the variable from the input will be inserted by replacing this token: {0}" });
Alexander
-
June 11, 2024 at 23:41 #37783
-
June 11, 2024 at 23:59 #37785
i was sing spjs.dffs.processEmailTemplate and it works fine but just doesn’t seem to work with alert
-
June 12, 2024 at 02:30 #37786
I am good. It works. thanks
-
June 12, 2024 at 04:00 #37787
Thank you for the resolving the email issues.
Now, I am running into a different issue –
1. I want to save the form
2. then send an email.Added this code for save – $(“input[id$=diidIOSaveItem]:last”).click();
But the input box appears and closes as soon as I added this line.
I tried changing the order to first send the email and then save but still the same behavior.
-
June 12, 2024 at 15:33 #37789
It is not possible to send it after the form is saved because the classic DFFS is using the built-in save function in SharePoint and you are automatically redirected away from the form when the save completes – effectively cutting off any ongoing custom code you have running.
You can modify it like this to send the email – and if it is successfully sent, the form is saved.
function sendCustomEmail(arg){ spjs.dffs.alert({ "title": "Enter a return reason", "msg": "<textarea style='width:100%;box-sizing:border-box;height;75px;' id='varFromAlertInput_input'></textarea>", "ok": function(){ var fromAlertInput = jQuery("#varFromAlertInput_input").val(); spjs.dffs.REST_Email({ "to": arg.to, "cc": arg.cc, "bcc": arg.bcc, "subject": arg.subject, "body": arg.body.split("{0}").join(fromAlertInput) }).done(function(success){ if(success){ spjs.dffs.triggerSave(); } }).fail(function(err){ alert("Sending failed with this error: " + err.responseJSON.error.message.value); }); }, "cancel": function(){ // Close dialog } }); } sendCustomEmail({ "to": ["alexander@spjsblog.com"], "cc": [], "bcc": [], "subject": "The subject of the email", "body": "The default body - the variable from the input will be inserted by replacing this token: {0}" });
-
-
June 12, 2024 at 15:33 #37788
got it working. thanks
-
-
AuthorPosts
- You must be logged in to reply to this topic.