XRM WebAPI Create new record using JavaScript in model driven app form command button
Here is a sample code which creates a child record from a command button on parent table form. This code is called from command button so you need to pass Primary Control parameter to javascript. Hope it works.