John Krasinski revealed that he refused to let his character Jim Halpert have an affair in The Office.

In the new book, Welcome to Dunder Mifflin: The Ultimate Oral History of The Office, Krasinski explained how the original script saw Jim cheat on Jenna Fischer's Pam while she was pregnant. "That's the only time I remember putting my foot down… I remember saying things that I never thought I'd say before, like, 'I'm not going to shoot it.'" the actor said. He added, "My feeling is there is a threshold with which you can push our audience. They are so dedicated. We have shown such great respect to them. But there's a moment where if you push them too far, they'll never come back. And I think that if you show Jim cheating, they'll never come back."

RELATED: The Office Theory Explains Why Andy Has Two Sets of Parents: Resentment

Greg Daniels, who adapted The Office for the United States and served as producer on the show, gave his thoughts on why Pam and Jim's problems were necessary. "I feel like that kind of worry was good in terms of the fans' engagement. I think they knew what was coming," he said. "They were very comfortable with the show they were getting, and I needed to worry them that maybe I was going to give them a bad ending so they were happy when they got a good ending."

Daniels explained that the cheating storyline was set to occur in the Season 8 episode titled "After Hours." The episode saw Jim spend more time with Cathy Simms, who was covering for Pam while she was on maternity leave. Cathy ended up staying in Jim's room, making numerous signals that left him feeling uncomfortable.

RELATED: Michael and Jan's Relationship Is The Office at Its Most Depressing

The Office ran for eight years and is still regarded as one of the most popular sitcoms ever. The show is shot in the style of a mockumentary that follows the manager and employees of Dunder Mifflin, a paper company in Scranton, PA. The film crew catches all the trials and mischief in the lives of the workers, inside and outside of the office.

The core cast included Steve Carell as Michael Scott, Rainn Wilson as Dwight Schrute, Angela Kinsey as Angela Martin, Ed Helms as Andy Bernard, Mindy Kaling as Kelly Kapoor and Ellie Kemper as Erin Hannon, to name a few. The show also featured many high-profile guest stars, including Will Ferrell, Idris Elba, Kathy Bates and Bob Odenkirk.

Welcome to Dunder Mifflin: The Ultimate Oral History of The Office is out now.

KEEP READING: The Office: NBCU Is 'Standing by' Whenever Greg Daniels Wants to Do a Reboot

Source: Welcome to Dunder Mifflin: The Ultimate Oral History of The Office, via New York Post