The following laws apply if you forgot to say Yaaleh Viyavo in Shemoneh Esrei:
If you remembered before saying Hashem’s name at the end of Retzei, go back, say Yaaleh Viyavo, and continue with Visechezenah.
If you remembered after completing Retzei but before beginning the next berachah, say Yaaleh Viyavo at that spot and continue with Modim.
If you remembered after beginning Modim, go back to the beginning of Retzei.
If you remembered after saying the second Yihiyu Leratzon, go back to the beginning of Shemoneh Esrei.
If the time of the next tefillah has already arrived, daven the next tefillah twice, the first time for that tefillah and the second time to make up for the previous tefillah.
If you forgot to say Yaaleh Viyavo during Shacharis and you have already davened Musaf, do not repeat the Shemoneh Esrei of Shacharis.
All the above also applies if you are unsure if you said Yaaleh Viyavo.