When we call upon God in our affliction, preparation must first be made. Note in this version the “Then.” Something must happen first. We have to make a change before God will rescue us, but the promise still stands:
Then call on me when you are in trouble,
and I will rescue you,
and you will give me glory.”
Psalm 50.15 NTL
The condition for God to hear our petitions is to fulfill our promises of the covenant with the Most High, v. 14. It does no good reciting his decrees and mouthing his covenant when we hate instruction and turn our backs upon his word, vv. 16-17.
Calling upon God in affliction means to show him our change of heart and stop treating him as if he were a human being, v. 21. If we don’t change, instead of rescue, God will tear us apart, v. 22. Repentance includes gratitude and walking in his ways, v. 23.
If we want God’s rescue, we must change our attitude and ways. Only then will it be possible to glorify him.