Hi
Thanks for reaching out to Microsoft Q&A.
Please check the below link with accepted answer for one the requirement similar to that of yours. You will have to check and tweak with reference to your need.
Please Upvote and Accept as answer if the reply was helpful, this will be helpful to other community members.