Your script doesn't seem to be committing the record after setting the xorder_id field. (BTW you should describe them as global fields - global variables are $$variables used in scripts).
You should be able to set a global from any context.
Three things to check.
Is GLOBALS::xorder_id set to global storage? you cant set an out of scope non global without making it in scope by establishing a relationship.
is TO1Orders::pkOrderID set to an auto enter value on creation? its got to have a value or the set field wont do anything.
is TO1Orders::pkOrderID set to an auto enter value on commit? If yes then new record, commit THEN set field.
Based on the script, the most likely culprit is your T01Orders::__pkOrder_ID field. Make sure that the relationship is seeing a value in that field. If the relationship is not resolving the way you expect it to, it my be setting the field...but just not with the value you are expecting.
May not matter regarding this particular problem but it looks like xSpecieID is being set to a space character, not a blank.
It looks like this:
Set Field[ Globals::xSpecieID; " " ]
Not like this:
Set Field[ Globals::xSpecieID; "" ]
pkOrderID is set to Generate on Commit.
I added Commit Records script step which seems to have resolved my issue, the Global variable now get set each time the script is run.
Thanks to all that responded
Just to reiterate, because this is important when you ask questions in the future.
It is NOT a Global VARIABLE. It is a Global FIELD.
You are correct, it is a Global field.
Thank you for pointing that out