Hi, First of all, this needs to be customized and cannot be set in the BC client.
Then there is no problem with the code shared by Mohana. You need to find a suitable trigger (Event) to run it, such as after the posting is completed, or after the Posted Purchase Invoice is created, etc.
Hope this helps as well.
Thanks.
ZHU