It is narrated from Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) said: "When Allah Almighty intends to create a soul, the angel appointed over the womb says: 'Ay rabbi, a-dhakarun am untha?' (O my Lord, is it a male or a female?) Then Allah Almighty makes His decree. Then the angel says again: 'Ay rabbi, a-shaqiyyun am sa'id?' (O my Lord, is it wretched or blessed?) Then Allah, the Mighty and Majestic, issues His command. Then the angel writes between its eyes everything it will encounter throughout its life, even the slight hardship or misfortune that will befall it."
Imam Abu Ya'la recorded it.
It is also narrated from Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) (through another chain) that the Messenger of Allah (peace and blessings be upon him) said: "When the drop of fluid settles in the womb, the angel appointed over the womb says: 'Ay rabbi, ma aktub?' (O my Lord, what shall I write?) Then Allah Almighty issues His decree. Then the angel asks whether it is a male or a female, and Allah, the Mighty and Majestic, issues His command" (and the narrator mentioned the complete hadith in the same way).
Imam al-Bazzar recorded it and said that the narrator Salih is alone in narrating it from al-Zuhri, that is, through Salim.
Hadith Referenceالمطالب العالية بزوائد المسانيد الثمانية / كتاب الإيمان والتوحيد / 2943
Hadith Gradingمحدثین:إسناده صحيح
Hadith Takhrij«حکم الحدیث المطالب العالیہ محققاً تنسیق د. سعد بن ناصر بن عبد العزيز الشَّثري- مکتبہ شاملہ :إسناده صحيح إسناده صحيح. ( مسند ابو یعلی برقم: 5775) » «انفرد به المصنف من هذا الطريق»