Please find that when K2 smart form is hosted inside an iframe say for eg: in CRM, you want to trigger K2 event from CRM button click, you can achieve this as below:
in CRM using javascript to call
iframe.contentWindow.postMessage("hi","*"); (if "*" doesn't work use server url +port like http://10.2.3.4:82)
Then use data label in view / form and put below in expression to listen to the event.
<script type="text/javascript">$(document).ready( function(){ var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";var eventer = window[eventMethod];var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; eventer(messageEvent, function (e) { if (e.data=="Validate") { $("[title='btnValidateToolTip']").trigger("click"); var txtValidation = $("[title='dtlValidationToolTip']").text(); e.source.postMessage(txtValidation, "*"); } else { $("[title='btnSaveToolTip']").trigger("click"); } }, true); });</script>
End