Home › Forums › Classic DFFS › Help with Custom JS
- This topic has 8 replies, 2 voices, and was last updated 3 years, 5 months ago by Jon Mortimer.
-
AuthorPosts
-
-
July 24, 2021 at 02:52 #34158
Hi, I am a newbie to Custom JS and was wondering if you could assist me with using {timestamp[hh/mm/yyyy hh.mm]} and the prepend function to add data to a field via setFieldValue? I’ve tried many variations and I’m just not familiar enough. Also, are there other internet sources that would provide some better understanding of custom JS?
-
July 24, 2021 at 09:08 #34162
Hi,
Custom JS is just a place to write JavaScript. There are of course a few internal DFFS functions that can be used, but it is basically just a place to put your own JavaScript code to do stuff in the form.Look at this thread for an example of how you can append text: https://spjsblog.com/forums/topic/recreating-multiline-text-field-with-append-changes-without-sp-versions/
Alexander
-
July 24, 2021 at 14:38 #34168
I may not be explaining correctly, sorry. I’m looking for specific examples of the append (and prepend “function”) when used with setFieldValue and timestamp. I have searched your site and have tried many different variations with no success. So either it’s not available to me in my environment or I’m doing it wrong. I’m assuming I’m doing it wrong.
I appreciate the link AND YOUR SUPPORT. I have revieved the link a few times and still have issues. The code is very specific to their needs. I imagine my needs would be a single line of code.
-
July 24, 2021 at 16:01 #34170
Sorry, I though you were looking for a custom js example – if it is in the set field value section in a rule you can look at the contextual help in that section.
Let me know if you have any further questions.
Alexander
-
July 25, 2021 at 15:25 #34173
Yes, I am looking for “specific custom JS examples” not a rule. In the custom JS, I would like to know how to use the timestamp and append/prepend to combine those with an existing field value.
Perhaps I’m not explaining it correctly. I have a variable with information. I want to take the current date and time (formatted as mm/dd/yyyy hh.mm) and add that, along with the contents of the variable into an existing field. Perhaps timestamp can only be used in a rule? Perhaps append/prepend can only be used in a rule? Perhaps that’s why you mentioned a rule? Not sure. I’m specifically looking to combine the above content and add that content to a field using customer JS. The former example you provided was not what I would expect to do something that, in my head at least, is a single line of code vs many lines of code..
-
July 25, 2021 at 17:47 #34175
The example I linked to did more or less what you are looking for, but appended text from one field that the user could see into another hidden field that had the complete log of all edits.
If you are using a variable and the user is not supposed to write the text you want to append you can use something like this:
var yourVariable = "some text to append"; var existingText = getFieldValue("MultilinePlainText"); var dateStamp = spjs.dffs.formatDate(new Date(), "MM/dd/yyyy HH.mm"); setFieldValue("MultilinePlainText", existingText + "\n\n" + dateStamp + "\n" + yourVariable);
Replace MultilinePlainText with the actual field name you want to append the text to.
Alexander
-
July 25, 2021 at 23:32 #34178
Thank you. I did what you provided and now get “Unable to get property ‘formatDate’ of undefined or null preference”.
-
July 26, 2021 at 08:39 #34180
Are you running the code in Custom JS or directly in the developer console in your browser (F12 > Console)?
The function spjs.dffs.formatDate was introduced in DFFS v4.4.3.60 in January 2019 – please ensure your DFFS version is this version or higher.
Alexander
-
-
July 26, 2021 at 15:55 #34184
Custom JS. The error appears when I went into console mode. I will check the versions.
-
-
AuthorPosts
- You must be logged in to reply to this topic.