Get user input prior to sending email

Home Forums Requests Get user input prior to sending email

Viewing 9 reply threads
  • Author
    Posts
    • #37777
      Rad
      Participant

        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 email

        Here’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);

      • #37778
        Alexander Bautz
        Keymaster

          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
        • #37779
          Rad
          Participant

            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

          • #37780
            Rad
            Participant

              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
              });

            • #37782
              Alexander Bautz
              Keymaster

                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

              • #37783
                Rad
                Participant

                  getting this error now.

                  POST
                  Email 400 (Bad Request)

                  • This reply was modified 6 months, 1 week ago by Rad.
                • #37785
                  Rad
                  Participant

                    i was sing spjs.dffs.processEmailTemplate and it works fine but just doesn’t seem to work with alert

                  • #37786
                    Rad
                    Participant

                      I am good. It works. thanks

                    • #37787
                      Rad
                      Participant

                        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.

                        • #37789
                          Alexander Bautz
                          Keymaster

                            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}"
                            });
                            
                        • #37788
                          Rad
                          Participant

                            got it working. thanks

                        Viewing 9 reply threads
                        • You must be logged in to reply to this topic.