Sorry for making confuse. Actually I have remove the event handler from form, no record is opening/refreshing to trigger flow any more. Here is the complete code:
function clickChooseTemplate(primaryControl) {
debugger;
var formContext = null;
if (primaryControl !== null) {
if (typeof primaryControl.getAttribute === 'function') {
formContext = primaryControl; //called from the ribbon.
} else if (typeof primaryControl.getFormContext === 'function'
&&
typeof(primaryControl.getFormContext()).getAttribute === 'function') {
formContext = primaryControl.getFormContext(); // most likely called from the form via a handler
}
}
var contactId = formContext.data.entity.getId().replace('{', '').replace('}', '');
var firstName = formContext.getAttribute("firstname").getValue();
var lastName = formContext.getAttribute("lastname").getValue();
var fullName = firstName + " " + lastName;
var templateName = "PRODUCT INSTRUCTION";
var params = {
"contact_GUID": contactId,
"contact_fullname": fullName,
"template_name": templateName
}
var url = "">prod-xx.canadaeast.logic.azure.com:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader('Content-Type', 'application/json');
console.log("Sending Request");
req.send(JSON.stringify(params));
Xrm.Utility.alertDialog("Flow initiated. The document will be generated soon.");
}
Thank you guys again. Next step I will create a dynamic flyout menu list buttons, will open another question if it need to help from you.