3 first letter from name and surname

Comments

5 comments

  • Hamid

    Hi sandra,

    Try with this code : 


    var a = @NameField.substring(0,3)
    var b = @NameField(" ")[1].substring(0,3)
    a+b
    1
    Comment actions Permalink
  • Sandra Jurkowska

    Hi Hamid, I tried and no, doesn't work --->> Script error: TypeError:  string is not a function.

    When I separated name and surname it is working.

    So in one field I have Name: John

    and in calculation field I have: 

    var name= @Name
    name.substr(0,3);

    And it is showed: Joh

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Sandra

    there's a typo in Hamid's code, must be 

    var b = @NameField.split(" ")[1].substring(0,3)

    Another issue: If there's a middlename like John Richard Smith the result would be JohRich. Middlenames could be handled in the code:

    var a = @NameField.split(" ");
    var b = a[1].substring(0,3);
    var c = a[a.length -1].substring(0,3);
    b+c

    But what about names with a suffix like John Smith jr.  or a prefix Dr. John R. Smith or J. R. Smith?  Or if you have John Smith and Johanna Smitter - both would have the same ID. Or Jo Smith = JoSmi (5 characters only).

    What I want to say: It's very difficult and dangerous to create an ID by using names. It only works correctly if everyone enters their names correctly and always in the same format. 

    Rainer

    1
    Comment actions Permalink
  • Hamid

    well seen Rainer :)

    0
    Comment actions Permalink
  • Sandra Jurkowska

    OK, great thanks!! It is working! I used a Hamid code with Your (Rainer) correction.

     

    I know Rainer, but in my data is only one name and surname (I have a data in polish)  and also I will use to my ID another fields like city, data and project number.

    One more time THANK YOU! :)

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk