Home › Forums › Classic DFFS › Recreating Multiline Text field with Append Changes without SP Versions…
- This topic has 13 replies, 3 voices, and was last updated 5 years, 7 months ago by BenR.
-
AuthorPosts
-
-
February 12, 2016 at 18:08 #10250
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 -
February 15, 2016 at 23:43 #10273
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
-
February 17, 2016 at 18:40 #10294
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 -
February 18, 2016 at 08:15 #10308
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
-
February 19, 2016 at 16:15 #10340
Alexander,
Perfect! Thank you for solving my problem!
R’grds – Ben.
-
June 8, 2018 at 11:30 #21128
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? thanksfunction 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.
-
June 8, 2018 at 11:49 #21132
Never mind, found there was a comma missing in your setFieldValue statement.
-
June 8, 2018 at 16:21 #21136
I’m glad you figured it out.
Alexander
-
November 6, 2018 at 09:59 #22694
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
-
November 6, 2018 at 17:13 #22698
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
-
November 6, 2018 at 17:29 #22700
Great idea, the result was “<P></P>”.
Thanks,
Phil -
March 29, 2019 at 20:10 #24550
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 -
March 30, 2019 at 09:20 #24557
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
-
April 1, 2019 at 13:37 #24565
Alexander,
Nicely done! This suits my application perfectly!
Hats off to you sir – I always appreciate your support and efforts!
R’grds – Ben.
-
-
AuthorPosts
- You must be logged in to reply to this topic.