Why shard failed exception is happening when trying to get a sub-string using scripetd fields?

You are still trying to use the field before checking that it exists. Have a look at this thread for an example of how to do it.