Write DFFS Email Send Date to list field

Forums Dynamic Forms for SharePoint Write DFFS Email Send Date to list field

Viewing 9 reply threads
  • Author
    Posts
    • #27424
      Mike
      Participant

      Spent some time searching through the forums and the DFFS backend but could not find the answer. I’m sending an email from DFFS and want to write the date and time sent to a field in the same list. That will allow us to calculate time spans from email send date to answer date (other list fields are updated by the email recipient).

      The email is launched from a DISPLAY form button using this HTML:

      <input type="button" onclick="spjs.dffs.processEmailTemplate('AssignmentEmail')" value="Send Assignment email">

      So need to write a date to a field when this email is processed from a DISPLAY form.

      Thanks for your help,
      Mike

    • #27449
      Alexander Bautz
      Keymaster

      You can use this in Custom JS:

      var date = new Date().toISOString();
      spjs.utility.updateItem({
          "listName": _spPageContextInfo.pageListId,
          "id": spjs.dffs.data.thisItemID,
          "data": {
              "YOUR_DATE_FIELD_NAME": date
          }
      });

      Alexander

    • #27455
      Mike
      Participant

      Unfortunately, this script updates the Date field whenever the Display form is opened or refreshed. The Date field should only capture the date (time is no longer needed) corresponding to when the DFFS email was sent. It could simply capture today’s date (and then never change if the Display or Edit form is opened). I could set this script to fire in a rule perhaps . . but it still needs something that will trigger when the email was sent (button pressed to start email process).

      Thanks
      Mike

    • #27457
      Alexander Bautz
      Keymaster

      Sorry for not giving you the full explanation. You must wrap this code in a function that you call from your button along with the call to spjs.dffs.processEmailTemplate.

      Add this to your Custom JS:

      function setDateFromBtn(){
          var date = new Date().toISOString();
          spjs.utility.updateItem({
              "listName": _spPageContextInfo.pageListId,
              "id": spjs.dffs.data.thisItemID,
              "data": {
                  "YOUR_DATE_FIELD_NAME": date
              }
          });
      }

      Then change your button like this:

      <input type="button" onclick="spjs.dffs.processEmailTemplate('AssignmentEmail');setDateFromBtn()" value="Send Assignment email">

      Alexander

    • #27461
      Mike
      Participant

      Works great Alexander. Just one final request: I’d like to have the date written to the field in the format MM/DD/YYYY, without the time, e.g., 10/23/2019.

      Thanks
      Mike

    • #27468
      Alexander Bautz
      Keymaster

      I misunderstood and thought you wanted to write the date to a date field and not a plain text field.

      Change this line:

      var date = new Date().toISOString();

      like this:

      var date = new Date().toLocaleDateString();

      Alexander

    • #27476
      Mike
      Participant

      Works great Alexander. Having the option to write to either a text field or a date field will come in handy.

      Thank you.
      Mike

    • #27599
      Mike
      Participant

      Alex,

      How can I ensure the above date variables return a chosen time zone, e.g., “America/Chicago” or GMT-5?

      I have a similar question related to using the timestamp variable in a Tab rule for ‘Set field value.’ Currently {timestamp[MM/dd/yyyy]} returns the UTC date. I would like to return a chosen time zone, e.g., “America/Chicago” for this field as well.

      Thanks,
      Mike

    • #27620
      Alexander Bautz
      Keymaster

      If you write the date to a date and time field as ISO8601 format (YYYY-MM-DD hh:mm:ss) SharePoint should show it correctly. You can also get the date representation for a specific timezone by using this approach, but it will not work in IE:

      new Date().toLocaleString("en-US", {"timeZone": "America/Chicago", "timeZoneName": "long"})

      Alexander

    • #27648
      Mike
      Participant

      Thanks Alex. This is working for custom JS.

      Mike

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