Hi gomathinetha,
I'm not sure what issues you actually got in detail, but the code should be working with on-premises as well. I have not however written this example, so would revert to the right people or would access assistance from the others in community. I'd recommend using the Yammer group where we have all the core team members included for these kind of questions. You can find the Yammer group for Office 365 Dev PnP project from following address - https://www.yammer.com/itpronetwork/#/threads/inGroup?type=in_group&feedId=4597220.
I'm not sure what issues you actually got in detail, but the code should be working with on-premises as well. I have not however written this example, so would revert to the right people or would access assistance from the others in community. I'd recommend using the Yammer group where we have all the core team members included for these kind of questions. You can find the Yammer group for Office 365 Dev PnP project from following address - https://www.yammer.com/itpronetwork/#/threads/inGroup?type=in_group&feedId=4597220.