This question came up recently on a Facebook group for people with service dogs. I thought it was a good question.
When getting x-rays done at the dentist, which I've had to do a lot over the past few months with all these dental problems I've had, I have Isaac do a down stay (which means he lies down and is told to stay) just outside the x-ray room, with the door open so he is within my sight. I wouldn't be comfortable having him outside the room if the door was closed or if I otherwise couldn't see him. I don't want him in the room when the x-rays are taken because I don't want him exposed to unnecessary radiation.
If it was necessary for him to be out of my sight, I would ask if a staff person would be willing to hold his leash for me or if there was an office he could wait in (with the door shut). Mind you, this is for a typical x-ray that would only take a couple minutes. If it was something lengthy like a bone density scan, I would not ask the staff to hold his leash or to put him in an office. They are not required to do either of those things anyway, and I wouldn't be upset at all if they declined for whatever reason, but I think in many cases they'd be happy to help in that way.
If I was going to have to have a lengthy x-ray procedure, like a bone density scan (which isn't really that lengthy, maybe 15 or 20 minutes, but longer than a regular x-ray like they do at the dentist), I'd either take someone with me that could hold the leash and watch Isaac while I was having the x-ray done or just leave him at home. Another option would be to call ahead and ask if there would be an office where he could stay during the procedure or to discuss other options. But I wouldn't just show up with my dog and expect the staff to make accommodations for watching him while I was unable to do so.
I'd do the same thing if I was having some other procedure other than an x-ray during which I would be unable to care for Isaac during the procedure. For instance, if you have an MRI, you have to hold perfectly still. Radiation isn't a concern with an MRI so he could be in the room with me during the procedure, but since you can't move at all, I wouldn't be able to give him commands if needed. So I wouldn't feel comfortable with that.
While doctors' offices, hospitals and other facilities that do x-rays are required to allow service dogs under the Americans with Disabilities Act, and you do not need to call ahead to let them know you'll be bringing a service dog with you to an appointment, if you're not sure if you're going to need x-rays, or not sure how long the x-rays will take, or not sure what will be the best thing to do with your service dog while the x-rays are taken, I recommended calling ahead to figure that stuff out before you show up for the appointment with your dog.