If the parties have agreed to or reached an understanding on the custody or temporary custody of their children, a copy of the agreement or an affidavit as to their understanding shall be attached to the petition or action. As promptly as possible after this filing, the court shall, except in exceptional circumstances, enter an order granting temporary custody in accordance with the agreement or understanding or in accordance with any stipulation of the parties.