Announcements
Hi,
I had a JavaScript that would bring up the Close Opportunity dialog box when a field value was changed to "No" in that Opportunity. This JavaScript was functioning in Dynamics CRM 2013, but since upgrading to CRM 2015 I get the error "Object doesn't support property or method 'OpportunityClose'"
Below is the JavaScript I'm using
function opportunityCloseDevelop(won) {
var decision = Xrm.Page.getAttribute("pacer_preparefordevelopstage").getValue();
if(decision == 590470001){
Mscrm.CommandBarActions.OpportunityClose(won);
}
}
The JavaScript is being called on the event OnChange for that field, where I'm passing the false parameter, since I want to close the Opportunity as Lost whenever the field value changes to No. How can I accomplish this?
Thanks
*This post is locked for comments
Hi,
Could you please help me on this ?
I know is late but i got working.
//JavaScript
//won
Mscrm.OpportunityCommandActions.opportunityClose(1);
//lost
Mscrm.OpportunityCommandActions.opportunityClose(0);
thanks in advance,
JP
The question's already got a verified answer, but I had a similar issue where Mscrm.CommandBarActions.OpportunityClose didn't work anymore in 2015. I believe the command simply changed.
Try using
Mscrm.OpportunityCommandActions.opportunityClose
instead with boolean values true/false
Library is also different: $webresource:Opportunity_main_system_library.js
Thanks! I decided to close the opportunity using a workflow, rather than using the javascript.
Hi Avneet,
I think Custom Code Validation 2015 tool will help you identifying if there is any unsupported function on your organization:
www.microsoft.com/.../details.aspx
You can also use F12 developer tools in the browser to debug your javascript code and check which is the exactly point you are having issues.
For more information, please check:
You are using the crm Internal method that's why it is failing. Use the below script that should close opportunity as won
function closeOpportunityAsWon() {
var opportunityId=Xrm.Page.data.entity.getId();
var xml = "" +
"<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">" +
"<s:Body>" +
"<Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">" +
"<request i:type=\"b:WinOpportunityRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">" +
"<a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>OpportunityClose</c:key>" +
"<c:value i:type=\"a:Entity\">" +
"<a:Attributes>" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>opportunityid</c:key>" +
"<c:value i:type=\"a:EntityReference\">" +
"<a:Id>" + opportunityId + "</a:Id>" +
"<a:LogicalName>opportunity</a:LogicalName>" +
"<a:Name i:nil=\"true\"/>" +
"</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>subject</c:key>" +
"<c:value i:type=\"d:string\" xmlns:d=\"www.w3.org/.../XMLSchema\">Won the Opportunity!</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"</a:Attributes>" +
"<a:EntityState i:nil=\"true\"/>" +
"<a:FormattedValues/>" +
"<a:Id>00000000-0000-0000-0000-000000000000</a:Id>" +
"<a:LogicalName>opportunityclose</a:LogicalName>" +
"<a:RelatedEntities/>" +
"</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>Status</c:key>" +
"<c:value i:type=\"a:OptionSetValue\">" +
"<a:Value>3</a:Value>" +
"</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"</a:Parameters>" +
"<a:RequestId i:nil=\"true\"/>" +
"<a:RequestName>WinOpportunity</a:RequestName>" +
"</request>" +
"</Execute>" +
"</s:Body>" +
"</s:Envelope>";
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseText;
alert(resultXml);
Xrm.Utility.openentityform(Xrm.Page.data.entity.getEntityName(),opportunityId)
}
André Arnaud de Cal...
294,099
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator