Its funny you asked this now, I just had a guy this weekend whose had several ham strains due to that exact issue. What you want to happen is the hamstrings to work as a knee flexor and not a hip extensor, while the glutes extend the hip. If the hams are trying to pull at both ends, you get that cramping sensation youre referring to. The easiest way to test this is with a swiss ball leg curl. You want the glutes to extend the hips to a level plane, then the hams curl with no cramping/pain. I would guess you will get that cramping when you try this at first.
Once you master the swiss ball you can progress to the glute/ham machine if you have one, or simply use weight plates under your feet for the leg curls.. Watch alex v's glute ham video, the way he is teaching it is the CORRECT way, which also makes sure the glutes fire into the pad, and the hams function from the KNEE. It makes it into a TRUE glute ham raise, not a low back/ham raise with shitty firing patterns that most people perform.