When the mortgagee or the mortgagee's assignee has served notice of intention to foreclose a mortgage, and within the period provided by such notice it is made to appear by the affidavit of the mortgagor, or any person claiming under the mortgagor, or the mortgagor's agent or attorney, to the satisfaction of a judge of the district court of the county where the mortgaged property is situated, that the mortgagor has a legal counterclaim or any other valid defense against the collection of the whole or any part of the amount claimed to be due on such mortgage, which proof must be made by affidavit stating the facts, but not on information and belief, such judge, by an order to that effect, may enjoin the mortgagee or the mortgagee's assignee from foreclosing the mortgage by advertisement and may direct that all further proceedings for the foreclosure thereof be had in the district court having jurisdiction of the subject matter. After the expiration of the period provided by the notice of intention, an order enjoining the foreclosure by advertisement shall be made only on motion or order to show cause. Notice of such motion, together with the affidavit used in support thereof, must be served upon the attorney or agent of the mortgagee or assignee in the same manner as service of other notices of motion, not less than eight days before the hearing thereon. The affidavit in support of the motion must state the facts upon which the application is made, may not be on information and belief, and must disclose a legal counterclaim or other valid defense to the collection of the whole or some part of the amount claimed to be due on the mortgage. Upon the hearing of the motion, the judge may enjoin the foreclosure of the mortgage by advertisement in the same manner as if the application had been made ex parte within the period of the notice of intention to foreclose. Service of the restraining order may be made upon the attorney or agent of the mortgagee or assignee, if the order was obtained ex parte, or if obtained on motion or order to show cause, it may be served upon the attorney or agent or upon the sheriff of the county where the foreclosure sale is to be had. If the notice of intention does not disclose the address of a resident agent or attorney, the order may be served upon such sheriff.
N.D.C.C. § 35-22-04