Show part of record field in grid

Sometimes i just can’t figure this out with scriptcase, i think it’s not that difficult but can’t seem to do it right.

I have a field with a first and lastname in the same field. I only want to show the lastname in the grid.

so in onrecord i…?

any ideas.

(Can’t split the field i two fields because the data is delivered this way from another external database, working on this ;-))

As long as you only have a first and last name it would go like this onRecord event:

$name = {name}; // User First and Last name

$parts = explode(" “, $name);
if(count($parts) > 1) {
$lastname = array_pop($parts); // User Last name
$firstname = implode(” ", $parts); // User First name
$firstname = $name;
$lastname = " ";

{first_name} = $firstname;
{last_name} = $lastname;

Or simply like this

{name} = $lastname;

and ignore this 2 lines:
{first_name} = $firstname;
{last_name} = $lastname;

But if you still have a middle name, it gets a little complicated …
Look at the picture.

1 Like

Thank you very much. This Will solve another problem i have :+1:

For this problem, there Will be middlenames. Is there a way to chop of the part before and after the first space. We know there Will be a space after the first name

I don’t know because I didn’t need to.
We write first:
Last Name, Midle name, First name
And then in the first part, Last and Midle are together.
We did not complicate further.
But I can take a look and test it a bit, and let you know if there will be a result.
It’s quite an interesting challenge.

i’m testing the function array_slice now no luck yet

This option also works - sort of like this:

$fullName = {name}; // User First Midle and Last name

$names = explode(’ ', $fullName);

$firstName = ‘’;

$lastName = $names[count($names)-1];

$middleName = ‘’;
if (count($names) > 1) {
$firstName = $names[0];
if (count($names) > 2) {
$middleName = implode(’ ', array_slice($names, 1, count($names)-2));

{first_name} = $firstName;
{midle_name} = $middleName;
{last_name} = $lastName;


that’s true. thanks. but some people are called something like

Gerard van der Vecht


And? Its not OK like this? :slight_smile:

yes that did the trick, i made a little adjusment so that it works for me.

this script uses a select to start a letter with 'dear ’ or ‘sir’ or ‘mis’ followed by lastname.

// aanhef

$volledige_naam = {bpv_pok_opgeleverd.bpv_contact_naam}; // naam uit veld

$naam = explode(’ ', $volledige_naam);

IF({bpv_mail_template.aanhef} = “1”)

$achternaam = $naam[count($naam)-1];
$tussenvoegsel = implode(' ', array_slice($naam, 1, count($naam)-2));

{AANHEF} = "Geachte " .  {bpv_pok_opgeleverd.bpv_contact_aanhef} . " " .  $tussenvoegsel . " " . $achternaam . "";

$voornaam = array_shift($naam);

{AANHEF} = "Beste " .  $voornaam . "";

thanks very much Rik

No problem, you’re welcome,
next time you will help me with some advice