This is a polite phrase that you use when someone turns down an invitation.
You can also use this in other situations to respond to different kinds of bad news. You may need to add some words depending on how bad the news is. For more serious bad news, you can say:
I'm so sorry to hear that.