All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
What you have referred to is not a Hadeeth, it is a saying of an unknown origin. Moreover, it contradicts what was authentically established on the authority of the Prophet, sallallaahu ‘alayhi wa sallam. Salmaan narrated on the authority of the Prophet, sallallaahu ‘alayhi wa sallam, that he said that nothing can fend off destiny, except supplication. [At-Tirmithi]
Ibn ‘Abbaas was reported to have said that caution avails nothing against destiny. However, Allaah The Almighty wipes from destiny whatever He wills through man's supplication. Ibn ‘Abbaas is also reported to have mentioned that supplication fends off destiny.
While circumambulating the Ka‘bah, ’Umar used to cry and supplicate Allaah The Almighty with an invocation that apparently indicated that it would change destiny. He used to supplicate Allaah The Almighty to change his destiny to be among the prosperous if he was already destined to be among the wretched, for Allaah The Almighty confirms and eliminates whatever He wills and He is able to do everything.
A similar report was narrated on the authority of Ibn Mas‘ood .
The supplication that you mentioned in the question is contrary to the admonishment of the Prophet, sallallaahu ‘alayhi wa sallam, to be decisive with one's supplication and not to make it conditional on something else, because nothing can force Allaah The Almighty to do something or prevent Him from doing anything. [Al-Bukhari and Muslim]
And Allaah Knows best.