2 Replies Latest reply on Jul 20, 2017 3:19 AM by WildwoodChris

    Initials for stamp from identity.name

    WildwoodChris

      Is it possible to generate initials for stamp from the identity.name field?  I can get the identity.name into my stamp (gives the whole name) and I can see JavaScript examples for extracting the initials from a 'Name' type field but I don't seem to be able to put them together.  What I want is for Adobe to read the identity.Name field, Joe Bloggs for example and put JB on the applied stamp.

       

      "event.value = identity.name" works fine for getting the full name into a stamp.

       

      I could use a scripts such as the below to ask with a pop up dialogue box: -

       

      var cAsk = "Enter your initials" ;

      var cTitle = "Initials";

      if(event.source.forReal && (event.source.stampName == "#G3wJtsfhyWcjjhWYZ5ombB"))

      {

        var cMsg = app.response(cAsk);

          event.value = cMsg;

        event.source.source.info.DocumentState = cMsg;

      }

       

      This would mean that you have to enter your initials every single time you use the stamp, so it's not really ideal.  The scripts I have gleaned from the web for extracting initials need the name field as a variable and I don't know how I can get identity.name to be used to extract the initials.  An example (which I can't get to work as it needs a 'function name' on line three apparently) is: -

       

      function(fn)

      {

      var  n=fn.split(" "),              // Split the full name into an array

        it="",                                  // Create and set the intials variable to nothing

        i;                                       // Set i to 0 for the while loop

      while(i<n.length)                // While loop that runs while i is smaller than the length of the array of names

      {

        it+=n[i][0];                         // Get the first letter from the name and add it to the it(initial) variable

        i++                                    // Increment i by 1

      }

      return(it.toUpperCase())    // Convert the initials to uppercase and then return it

      }

       

      There are other examples of extracting initials out there such as: -

       

      https://stackoverflow.com/questions/33076177/getting-name-initials-using-js

      https://stackoverflow.com/questions/8133630/spliting-the-first-character-of-the-words

      https://gist.github.com/cvergne/7244472d3e1f1ca7ee56

      https://gist.github.com/ivankahl/7491724#file-initials-in-140bytes-annotated-js

       

      Is anyone able to help or has achieved this in a different way?  Is the getInitials function an available option?  Any help would be appreciated - thanks!

        • 1. Re: Initials for stamp from identity.name
          try67 MVP & Adobe Community Professional

          You can use this code:

           

          event.value = getInitials(identity.name);
          
          function getInitials(string) {
              var names = string.split(' '),
                  initials = names[0].substring(0, 1).toUpperCase();
             
              if (names.length > 1) {
                  initials += names[names.length - 1].substring(0, 1).toUpperCase();
              }
              return initials;
          }
          

           

          I took the getInitials code from one of the links you provided and adjusted it a bit to work in this context, but I didn't test it.

           

          One problem I can think of is with hyphenated names like "John-Jack". The result for that will not be "JJ", but just "J"... This can be accounted for by replacing all hyphens with a space in the getInitials function.

          1 person found this helpful
          • 2. Re: Initials for stamp from identity.name
            WildwoodChris Level 1

            Thank you so much!  I tried that code in the stamp and it works beautifully.

             

            I think the hyphenated names shouldn't be too much of an issue. I will roll it out and see what comments I get!  Thanks again.