Sammy Davis Jr. agreed to make a guest appearance because he was a good friend of Sidney Sheldon. Unfortunately, Larry Hagman could be notoriously difficult if he felt upstaged by a bigger star than himself, and tensions soon escalated on set. Barbara Eden, who usually kept out of such things, had a private talk with Sammy to convince him to stay and finish filming the show.
On January 10th 1967, while filming his guest appearance, Sammy Davis Jr. visited the set of fellow Screen Gems production The Monkees (1965). He reportedly filmed a cameo with them as well, although the footage, if any, has never been seen.
Entertainer Sammy Davis, Jr. plays himself but does more than just perform. He has scripted lines and a part in the plot as a character, albeit still as Davis. Thus his closing credits do not credit him in the usual manner "as Himself", but "as Sammy Davis, Jr." as he is literally PLAYING himself rather than BEING himself.