Getting the name of a held item

how would I go about getting the name of a held item, I have currently got it to use the item itself with SelectedItem but I want to use the custom name.

ex. foo:bar contains: $say $(custom_name)

while holding a sword named "hello" and using the command:

/function foo:bar with entity @s custom_name

expected result:

A message in chat saying hello

Continue to help post