Recreating Multiline Text field with Append Changes without SP Versions…

Home Forums Classic DFFS Recreating Multiline Text field with Append Changes without SP Versions…

Viewing 13 reply threads
  • Author
    Posts
    • #10250
      BenR
      Participant

        Alexander, savvy users,

        I am trying to create a “log” multiline text field that has the features of the SharePoint “Append Changes to Existing Text,” but is not reliant on SharePoint’s versioning (which have many disadvantages).

        In my scenario, I have a two multiline text fields, [Log] and [LogHistory], both plain text only. I would like to use the Set Field for [LogHistory] to a value of “prepend:{timestamp} – {currentUser}: \n{Log}\n************\n”, and when applied to a “The form is saved” rule, it is lovely.

        However, if the user DOES NOT ENTER a value into the [Log] field, the {timestamp} – {currentUser} is prepended to the [LogHistory] field with no [Log] value – which I would like to avoid.

        I have very limited coding skills. Can anyone recommend a methodology to check that [Log] has some characters before prepending to the [LogHistory] field? I cannot use a DFFS Rule to check the contents of a multiline text field…

        Any input is appreciated!

        R’grds – Ben.
        My Environment: SharePoint 2013, dffs_min – v3.352, spjs-utility – v1.257, jquery-1.10.2.min

      • #10273
        Alexander Bautz
        Keymaster

          Hi,
          You can use two rules to check if the field is empty, but it’s probably cleaner to use this custom function in the Custom JS – and trigger it from the “The form is saved” rule (in the “Run these functions / trigger these rules” section).

          function logHistory(){
          	var a = getFieldValue("Log"), b = getFieldValue("LogHistory"), c, d = spjs.utility.userInfo(spjs.dffs.data.currUserID);
          	if(a !== ""){
          		c = new Date().toLocaleString(_spPageContextInfo.currentCultureName);
          		setFieldValue("LogHistory",c+" - "+d.Title+"\n"+a+(b!==""?"\n"+b:""));
          		// Clear the Log field
          		setFieldValue("Log","");
          	}
          }

          Let me know how this works out.

          Alexander

        • #10294
          BenR
          Participant

            Alexander,

            Unfortunately, I am at dffs_min – v3.352, where [The form is saved] trigger only executes the [Set field value] section, and does not executes [Run these functions].

            You mention that two rules could accomplish the same (though not as cleanly), but I don’t see how as a rule cannot be created for a [Multiple Lines of Text] field. Can you guide me to the less-clean solution?

            Greatly appreciate your effort! R’grds – Ben.
            My Environment: SharePoint 2013, dffs_min – v3.352, spjs-utility – v1.257, jquery-1.10.2.min

          • #10308
            Alexander Bautz
            Keymaster

              No problem, just skip the rule, and change the function name to “dffs_PreSaveAction” like this:

              function dffs_PreSaveAction(){
              	var a = getFieldValue("Log"), b = getFieldValue("LogHistory"), c, d = spjs.utility.userInfo(spjs.dffs.data.currUserID);
              	if(a !== ""){
              		c = new Date().toLocaleString(_spPageContextInfo.currentCultureName);
              		setFieldValue("LogHistory",c+" - "+d.Title+"\n"+a+(b!==""?"\n"+b:""));
              		setFieldValue("Log","");
              	}
              	return true;
              }

              DFFS will automatically trigger this function on save.

              Alexander

            • #10340
              BenR
              Participant

                Alexander,

                Perfect! Thank you for solving my problem!

                R’grds – Ben.

              • #21128
                Phil Grant
                Participant

                  Hi,
                  I’ve tried this in my DFFS but I keep getting a Javascript error, not sure why, I’ve tried using field names and internal field names but both cause the error, any ideas what I’m doing wrong? thanks

                  
                  function logHistory(){
                  var a = getFieldValue("Additional CCB Comments"), b = getFieldValue("CCB Comments"), c, d = spjs.utility.userInfo(spjs.dffs.data.currUserID);
                  if(a !== ""){
                  c = new Date().toLocaleString(_spPageContextInfo.currentCultureName);
                  setFieldValue("CCB Comments" c+" - "+d.Title+"\n"+a+(b!==""?"\n"+b:""));
                  // Clear the Log field
                  setFieldValue("Additional CCB Comments","");
                  }
                  }
                  • This reply was modified 6 years, 5 months ago by Phil Grant.
                  • This reply was modified 6 years, 5 months ago by Phil Grant.
                • #21132
                  Phil Grant
                  Participant

                    Never mind, found there was a comma missing in your setFieldValue statement.

                  • #21136
                    Alexander Bautz
                    Keymaster

                      I’m glad you figured it out.

                      Alexander

                    • #22694
                      Phil Grant
                      Participant

                        Alexander,
                        I’ve been using the code above for a while and noticed that the ‘if’ statement seems to fail to catch an empty field, the date and user ID is always added to the log field even if new comment field is empty, this results in long strings of times and names when nothing was changed.

                        Not sure why this would happen.

                        Phil

                      • #22698
                        Alexander Bautz
                        Keymaster

                          Not sure, but if your comments field is not plain text it will not be empty like “” when using getFieldValue. Try running this in the console when the field is empty (hit F12 and select Console):

                          getFieldValue("Your_comment_field_internal_name);

                          Try using the value returned in your if statement.

                          Alexander

                        • #22700
                          Phil Grant
                          Participant

                            Great idea, the result was “<P>​</P>”.

                            Thanks,
                            Phil

                          • #24550
                            BenR
                            Participant

                              Alexander,

                              I am still using this method, though I am on all current versions… I would like to change the format of the date & time to match what is displayed in the Created and Modified fields – for me, I see: “Created at 3/25/2019 11:06 AM”

                              I am using: c = spjs.dffs.buildValStr(“{timestamp[M/d/yyyy hh:mm]}”); which gives me: 3/29/2019 3:07.

                              How can I get the AM / PM portion?

                              As always, I’m so appreciate your support and efforts!

                              R’grds – Ben.
                              Reference: Dynamic Forms for SharePoint v4.4.3.64 – March 13, 2019|CSS version: 4.46 / 4.46|spjs-utility version: 1.332

                            • #24557
                              Alexander Bautz
                              Keymaster

                                Hi,
                                If you use DFFS v4.4.3.60 or newer (like I see that you do) you can use this format:

                                spjs.dffs.buildValStr("{timestamp[dddd MMMM dd, yyyy hh:mm am/pm]}");

                                Alexander

                              • #24565
                                BenR
                                Participant

                                  Alexander,

                                  Nicely done! This suits my application perfectly!

                                  Hats off to you sir – I always appreciate your support and efforts!

                                  R’grds – Ben.

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