The script must be pasted on the corresponding document at:

Settings->Purchase/sales->Documents->Run SQL

Indicative for use for loyalties collection feature copy and the following code to receipt:

and the following to return: