var ewt = ewt || {};
ewt.ewt_CreateChiledOpportunity = function ()
{
    var dual = false;
var parentOpportunityId =null;
var chiledOpportunityId =null;
function Form_onLoad(){
    
        
    }
    function CreateChiledOpportunity(){

var serverURL = Xrm.Page.context.getClientUrl();


var actionName = "ewt_CrateChiledOpportunityAction"; // Global Action Unique Name


//Pass the input parameters of action
var data = {
"parentopportunityid": Xrm.Page.data.entity.getId().replace('{', '').replace('}', '')
};

var req = new XMLHttpRequest();

req.open("POST", serverURL + "/api/data/v9.1/"+actionName, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function() {
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 200) {
//You can get the output parameter of the action with name as given below
result = JSON.parse(this.response);

} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
//Execute request passing the input parameter of the action
req.send(window.JSON.stringify(data));
}


return {
'Form_onLoad': Form_onLoad,
'CreateChiledOpportunity': CreateChiledOpportunity
    };
}();