Welcome to the Atlassian developer community @GaryLeung,
I don’t have an answer to your question, but I have a comment about using that code: