Their relationship was not very good in general. It is unknown when they started dating but it's known that they separated in the "Pilot" and they officially were divorced in "Twenty-Five Little Pre-Pubers Without A Snoot-ful".
In Big Flappy Bastards, Alan goes to Judith’s place to help her with house chores. His original intentions are that he loves her and wants her back. When Charlie suggests to Alan that he is being used, Alan snaps at Charlie, denies his assumptions and leaves. Afterwards, when fixing a leaky sprinkler, Alan tells Judith that he's had enough trying to win her back and that she is free, the two end up sharing a kiss, making him stay with her. Later on, Alan realizes that his marriage is over when Judith explains that she kissed him only because she was afraid of him leaving her.
Judith said that they could not continue their relationship because she had become a lesbian, but in "Alan Harper, Frontier Chiropractor" it was confirmed that that was only an excuse to divorce Alan. Judith finally reveals in "A Pot Smoking Monkey" that she always detested Alan, even before they committed (after he went to Judith's house and asked if he could ask for a divorce lawyer for Alan and Kandi. But she said no because she represented her and then Alan asked Judith when she began to hate him so much).
Despite all this, Judith and him also had good times. For example, in the episode "Go Get Mommy's Bra", when she broke up with her boyfriend Greg and was sad, Alan went to genuinely comfort her. She accepted his kindness and rested on his shoulder as he hugged her. They soon made out and were about to have sex until Charlie and Jake arrived at home, interrupting the encounter. It was likely this brought up old feelings, as in "Carpet Burns and a Bite Mark", they began to date again and had sex, something they both enjoy but after getting into yet another argument with her, Alan decides not to see her anymore.
When she sees he is dating Kandi, she is disgusted but Alan only rubs it in her face before he remarks on her last suitor. This is further backed up by Charlie, causing Judith to leave in disgust while Alan launches further taunts. A rare time, he has a victory over her.
However, when Alan suffers a divorce from Kandi, Judith only rubs it in that he'll still pay her alimony.
When she and Herb have marital problems in "It's Always Nazi Week", Alan is pleased at her second failed marriage and went to see her house to gloat. After she broke down, he comforted her while he secretly took pleasure in her sadness but said she was still attractive for her age, as she was surprised at this. Judith then threw herself at him by kissing him intently, which surprised him before they have an affair by having sex.
In "Cab Fare and a Bottle of Penicillin", Alan goes to talk with Judith. She and Alan briefly reunite over their lives and share a kiss but its awkward, they try to leave it but kiss again and drunkenly have sex while getting engaged. Alan attempted to explain but was halted by Judith's promises and continuing to throw herself at him. The relationship comes to an end when Judith finds out that Alan proposed to Lyndsey before her. Judith kicked Alan in his groin, for deceiving her while Walden took pleasure in witnessing the scene.