When you do any menu item it executes some mel. You can find out what it executes by enabling “History:Echo All Commands” in the script editor. In your case the command executed was
AttachSelectedAsSourceOfField
Which you can call, but in this case that is is a mel wrapper for the actual command. You can search for these mel calls in the maya scripts area. If you look at the file:
mayalocation/scripts/startup/defaultRunTimeCommands.mel
It defines the command:
runTimeCommand -default true
-annotation _L10N(kAttachSelectedAsSourceFieldAnnot,"Select field, then select object to be its source")
-category ("Fields")
-command ("addDynamic")
AttachSelectedAsSourceField;
So it actually calls “addDynamic”. You can find an explanation of addDynamic in the help doc under technical doc:commands.
You could try and manually do all the connections instead of using the command, but you might miss something or a setting somewhere. You can use window:hypergraph:connections to examine what was set up by the command. If you are really stumped you could save ascii versions of the scene before and after the command, then run a utility like xdiff the two scenes.