Good afternoon, Necessary to prevent the opportunity to be saved according to the code below, however it is saving the record usually: I'm using econtext.getEventArgs method, however unsuccessfully. VerificaOportunidadeAberta function (econtext) { eventArgs econtext.getEventArgs = var (); if (Xrm.Page.ui.getFormType () == 1) { if (Xrm.Page.getAttribute ("ownerid"). getValue ()! = null) { Owner Xrm.Page.getAttribute var = ("ownerid") getValue () [0] .id.; Family Xrm.Page.getAttribute var = ("new_idfamilia") getValue ().; var Customer = Xrm.Page.getAttribute ("new_idclienteprovavel") getValue ().; var status = Xrm.Page.getAttribute ("new_statusauxiliar") getValue ().; var req = new XMLHttpRequest (); req.open ("GET", encodeURI (Xrm.Page.context.getClientUrl () + "/XRMServices/2011/OrganizationData.svc/new_oportunidadecontroleSet?$select=new_idclienteprovavel,new_idcriadopor,new_idfamilia,statecode&$filter=new_idcriadopor eq '"+ Owner +"' and statecode / eq Value 0 "), true); req.setRequestHeader ("Accept", "application / json"); req.setRequestHeader ("Content-Type", "application / json; charset = utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var = returned JSON.parse (req.responseText) .d; var results = returned.results; for (var i = 0; i <results.length; i ++) { var new_idclienteprovavel = results [i] .new_idclienteprovavel; var new_idcriadopor = results [i] .new_idcriadopor; var new_idfamilia = results [i] .new_idfamilia; var = statecode results [i] .statecode.Value; } alert (new_idclienteprovavel) alert (new_idcriadopor) alert (new_idfamilia) alert (statecode) if (Owner == new_idcriadopor) {Alert ("Prop") if (client == new_idclienteprovavel) {Alert ("Customer") if (Family == new_idfamilia) {Alert ("Family") if (statecode == 0) {Alert ("Active") if (eventArgs.getSaveMode () == 1 || eventArgs.getSaveMode () == 2) // manual save or save XRM {Alert ("order") alert ("! Attention There is already an Opportunity to Open with the same Family for this client."); eventArgs.preventDefault (); alert (eventArgs.preventDefault ()); } } } } } } else { alert (this.statusText); } } }; req.send (); } } } Thank you
↧