Expand my Community achievements bar.

SOLVED

Concatenating the initials of names from last, first and middle initials from one field name.

Avatar

Level 4

Hi All,

Good day. Please I am having problem writing script to cocatenate the first letter of the last name, first letter of the first name, and the middle initial from a name field.

Is there an example I can use.

Thanks

v/r

Tammy

1 Accepted Solution

Avatar

Correct answer by
Level 5

Tammy,

Could you please give one Rater- Name example?

I assumed the Rater - Name is "Mathew Easow Jacob"

Try below script on Rater-initial Field.

var names = Rater_Name.rawValue.split(" ");

var initials="";

for(i = 0; i<names.length; i++ ){

          initials = initials +names[i].charAt(0);

     }

this.rawValue = initials;

Below is the Screenshot.

Untitled.png

Let me know if you need some more information.

Vjay

View solution in original post

5 Replies

Avatar

Level 5

Hi Tammy,

Keep below script on the result field where you wanted to get First Char of (First and Last Name) and Middile Initial from Name.

Language - JS and Event - Calculate.

// Last.rawValue.charAt(0)      -      gets first char of the last Name

// First.rawValue.charAt(0)      -      gets first char of the First Name

// Middle.rawValue.charAt(Middle.rawValue.search(" ")+1)      -      gets Middle Initial of the Name.

this.rawValue = Last.rawValue.charAt(0) + First.rawValue.charAt(0) + Middle.rawValue.charAt(Middle.rawValue.search(" ")+1);

Example

     First Name : Mathew, Last Name : Jacob, Name: Mathew Easow Jacob

     Result will be : JME

Let me know if this helps ..

Vjay

Avatar

Level 4

Vjay,

Good morning, and thank you for the code. It is not working right.

Are you assuming that there are 3 different fields called Lastname, Firstname, and Middlename?

There is only one field called Rater_Name, which should have a last name, first name, and middle name entered into it. This Rater_Name entered should concatenate into an initial field called RaterInitial.

I was thinking that since there are no distinct fields, that a script that will concatenate the first character of any words entered into the Rater_Name field after any space or comma could work, but I do not know how the script will look like.

Thanks

v/r

Tammy

Avatar

Level 4

Hi All,

I wrote the following script to see if it will extract the first character of the Lastname  in Rater-Name.

var psny=xfa[0].form[0].form1[0].page1[0].Rater_Name[0].rawValue;

form1[0].Page1[0].RaterInitial[0].rawValue=Substr(psny, 1, 1 );

It actually extract the first character of the input, however, I do not know how to add the search for the next words which will be the first name, and middle name, and also add to the code for it to rextract their first characters.

I need help with this.

Thanks

v/r

Tammy

Avatar

Correct answer by
Level 5

Tammy,

Could you please give one Rater- Name example?

I assumed the Rater - Name is "Mathew Easow Jacob"

Try below script on Rater-initial Field.

var names = Rater_Name.rawValue.split(" ");

var initials="";

for(i = 0; i<names.length; i++ ){

          initials = initials +names[i].charAt(0);

     }

this.rawValue = initials;

Below is the Screenshot.

Untitled.png

Let me know if you need some more information.

Vjay

Avatar

Level 4

Thanks a lot Vjay, you saved my day!