Help with Custom JS

Forums Dynamic Forms for SharePoint Help with Custom JS

Viewing 7 reply threads
  • Author
    Posts
    • #34158
      Jon Mortimer
      Participant

      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?

    • #34162
      Alexander Bautz
      Keymaster

      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

    • #34168
      Jon Mortimer
      Participant

      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.

    • #34170
      Alexander Bautz
      Keymaster

      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

    • #34173
      Jon Mortimer
      Participant

      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..

    • #34175
      Alexander Bautz
      Keymaster

      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

    • #34178
      Jon Mortimer
      Participant

      Thank you. I did what you provided and now get “Unable to get property ‘formatDate’ of undefined or null preference”.

      • #34180
        Alexander Bautz
        Keymaster

        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

    • #34184
      Jon Mortimer
      Participant

      Custom JS. The error appears when I went into console mode. I will check the versions.

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