Produce Sort Artist Field

The intent of this action is to rearrange the contents of the Artist field to last name, first name order, saving the results to the Sort Artist Field. The action correctly handles the presence of multiple artists separated by the multi-value delimiter (;;;). If an artist name already contains a comma, it is assumed to already be in last name, first name order. If a comma is not present, the last name is assumed to start at the last space in the name.

----- Start of action 'Produce Sort Artist Field'

Force Grouped Execution

Extract and rearrange the contents of the Artist field such that first and last names are flipped. The field may contain multiple artists separated by the multi-value delimiter (;;;).

The last name is determined by breaking an 'artist' value at the first space from the end of the field.

The rearranged content is saved to the Sort Artist field

'

If you do not want to overwrite an existing Sort Artist field, enable the following statements. If you do so you can disable the 'Clear the Sort Artist field' statement as it will always be empty.

# Test if the Sort Artist field is empty (Set result)

# Exit if false

'

Make sure Sort Artist is empty

Clear the Sort Artist field

'

Call action do1artist with Variable 1 containing a single artist.

Repeat With Variable 1 for the list in field Artist (Initial) string delimiter "\m" Run inline action 'do1artist' grouped

'

... end of action

Start do1artist -

Process a single artist value in Variable 1. Accumulate the possible modified artist in the Sort Artist field

'

See if there is already a comma in the artist name.

Split Field Variable 1 at delimiter "," save right portion to Variable 2

if true

'

If the artist already has a comma in its name, assume that it is already 'last name, first name' . Rewrite it to ensure it has the comma-space formatting

Set Variable 1 to "\v1, \v2"

else

'

Split the field at the rightmost space

Split Field Variable 1 from the end at delimiter " " save right portion to Variable 2

if true

'

If we don't fall in here, the artist in Variable 1 has a 'single' name.

If we have a 'last' name, flip the first and last delimiting them with a comma-space.