0

CRM의 작업을 취소 할 수있는 사용자 지정 단추가 있습니다. 사용자 정의 버튼은 작업을 취소하는 자바 스크립트를 트리거합니다. blog by Guru Prasad을 기반으로 스크립트를 만들었습니다.CRM 2016 Javascript가 새 CRM 터보 양식과 함께 작동하지 않습니다.

이전에는 CRM 2013에서 사용했지만 CRM 2016으로 업그레이드 한 후에는 더 이상 작동하지 않습니다. 버튼을 클릭해도 아무런 작업도 수행되지 않습니다. 오류 메시지 등은 CRM 2016의 새로운 Turbo Form 기능으로 인해 작동하지 않습니다. 기존 양식을 사용하기 위해 Turbo Form을 끈 경우 작업 취소 버튼이 정상적으로 작동합니다.

다음은 내 스크립트입니다. 스크립트가 CRM 2016 Turbo Form 기능과 함께 작동하지 못하게하는 것이 있으면 알고 계십니까?

PS : 전문가 프라 사드의 블로그에 처음 코드는 여전히 getServerUrl()을 사용하고 있지만, msdn link에 따라 우리가 우리의 스크립트를 업데이트하는 getClientUrl()에 사용되지 않으며 변경되었습니다 -하지만 여전히 작동하지 않습니다.

function cancelTaskRecord(RECORD_ID) { 
    //set Task record to Cancel status, then force to close the page 
    Xrm.Page.data.save().then(changeRecordStatus(RECORD_ID, 2, 6), Xrm.Page.ui.close()); 
} 

function changeRecordStatus(RECORD_ID, stateCode, statusCode) 
    { 
    // create the SetState request 
    var request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"; 
    request += "<s:Body>"; 
    request += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"; 
    request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">"; 
    request += "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">"; 
    request += "<a:KeyValuePairOfstringanyType>"; 
    request += "<c:key>EntityMoniker</c:key>"; 
    request += "<c:value i:type=\"a:EntityReference\">"; 
    request += "<a:Id>" + RECORD_ID + "</a:Id>"; 
    request += "<a:LogicalName>task</a:LogicalName>"; 
    request += "<a:Name i:nil=\"true\" />"; 
    request += "</c:value>"; 
    request += "</a:KeyValuePairOfstringanyType>"; 
    request += "<a:KeyValuePairOfstringanyType>"; 
    request += "<c:key>State</c:key>"; 
    request += "<c:value i:type=\"a:OptionSetValue\">"; 
    request += "<a:Value>" + stateCode + "</a:Value>"; 
    request += "</c:value>"; 
    request += "</a:KeyValuePairOfstringanyType>"; 
    request += "<a:KeyValuePairOfstringanyType>"; 
    request += "<c:key>Status</c:key>"; 
    request += "<c:value i:type=\"a:OptionSetValue\">"; 
    request += "<a:Value>" + statusCode + "</a:Value>"; 
    request += "</c:value>"; 
    request += "</a:KeyValuePairOfstringanyType>"; 
    request += "</a:Parameters>"; 
    request += "<a:RequestId i:nil=\"true\" />"; 
    request += "<a:RequestName>SetState</a:RequestName>"; 
    request += "</request>"; 
    request += "</Execute>"; 
    request += "</s:Body>"; 
    request += "</s:Envelope>"; 

    //send set state request 
    $.ajax({ 
     type: "POST", 
     contentType: "text/xml; charset=utf-8", 
     datatype: "xml", 
     url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", 
     data: request, 
     beforeSend: function (XMLHttpRequest) { 
      XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*"); 
      XMLHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"); 
     }, 
     success: function (data, textStatus, XmlHttpRequest) { 
      Xrm.Page.ui.close(); 
     }, 
     error: function (XMLHttpRequest, textStatus, errorThrown) { 
      alert(errorThrown); 
     } 
    }); 

} 
+0

아무 일도없는 것 같습니다. 제대로 작동해야합니다. 코드가 트리거되는지 확인 했습니까? 'save(). then'은 유효성 검사 오류가 없거나 저장을 방해하는 사용자 정의 코드가있는 경우에만 작동합니다. – dynamicallyCRM

+1

내 스크립트의 경고 팝업창에 몰래 들어 와서 터보 양식의 사용 여부와 상관없이 트리거합니다. 작동하지 않는 취소 작업 부분입니다. 취소 작업은 터보 양식이 꺼져있을 때만 작동합니다. 스크립트에 터보 폼이 활성화되어 있으면 작동하지 않는 것이 있습니까? 또한 스크립트에서 save(). then 부분을 제거했으며 터보 양식이 활성화되어있을 때 여전히 아무 것도 취소하지 않습니다. – ichachan

답변

1

귀하의 의견은 두 경우 모두 코드가 실행되고 있다고 언급했습니다. 즉, SetState 요청을 수행하기위한 실제 Jquery 호출 문제가 있음을 의미합니다. 다음 단계는 두 가지입니다. 실제로 두 경우 모두에서 요청을 보내고 있습니까 (Jquery가 올바르게로드되고 있습니까). 그리고 동일한 요청이 전송됩니다. 경고가있는 경우 코드에 중단 점을 배치하고 두 경우 모두에서 jquery가 작동하는지 확인할 수 있습니다. 또한 피 들러를 설치하고 터보 양식과 레거시의 요청을 비교하여 요청이 동일한 지 여부를 확인할 수 있습니다.