Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Split full name into first and last name for a pre-populated field

Avatar

Former Community Member

Hello,

Can any one please advise how I can split a full name like "Smith,John T" into "John Smith" without middle initial for a field that pre-populated by a web service. Note that the format will always be the same like last name comma firstname (without space) and middle initial. I tried different way but it does not seem to work as expected.

Thank you in advance,

Han Dao

5 Replies

Avatar

Level 10

You can try the below code to get what you want..

//Get the Last name
var arrLastName = TextField1.rawValue.split(",");
var LastName = arrLastName[0];

//Get the First name
var arrFirstName = arrLastName[1].split(" ");
var FirstName = arrFirstName[0];

xfa.host.messageBox("" + FirstName + " " + LastName);

Thanks

Srini

Avatar

Former Community Member

Hi Srini,

I try to place your code in the calculate event but it does not seem to work. Can you advise what event should I try to make it work.

Thanks,

Han Dao

Avatar

Level 10

Try placing the code in the initialize event of the field which is prepopulated with the User Name data from Webservice.

And then change the "TextField1.rawValue" to "this.rawValue".

Thanks

Srini

Avatar

Former Community Member

Hi Srini,

Well, actually the web service is not execute until user fill the empID and press enter for other fields such as full name to populate. So it seems like a litle tricky here that I need to split that full name after the above occurs. I tried to place the code in the initialize event but it does work.

Han

Avatar

Level 10

Then the code might need to be placed in the event that executes Webservice code.

Probably after the code to execute webservice, place the above code and use the proper field name, that will hold the User Name value from the Webservice.

If you have using the Execute button to execute the webservice, then you might need to place the code in a separate button which is set to Regular type.

Set the visible property of the Execute button to "invisible".

In the click event of the Regular button make a call to Click event of Execute button.

Click event Script: Java Script

//Submit the Data to the Webservice
Page1.ExecWebService.execEvent("click");

//Then place the bove code to get the User name..

Thanks

Srini