My question is can we make a function in postman and declare it global that we can access throughout the workspace? is it possible if yes how we can do this?
With V11 of Postman, you can use the Package Library to create scripts at the team level and call these into a Collection at the different script levels.
https://learning.postman.com/docs/tests-and-scripts/write-scripts/package-library/
I create a few helper utils and added them to a gist:
https://gist.github.com/DannyDainton/dd098b730a643f2d2be9b544953ccb5b