Maslamah bin Mukhallad came to Sayyiduna Zayd bin Thabit (may Allah be pleased with him) and said: O my cousin, we have been compelled to judge. Sayyiduna Zayd (may Allah be pleased with him) said: Judge in accordance with the Book of Allah. If it is not in the Book of Allah, then judge in accordance with the Sunnah of the Messenger (peace and blessings be upon him); otherwise, summon the people of sound opinion and consult them, then exercise your own judgement (ijtihad) and choose your own view; there is no harm in it.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20345