Wednesday 7 October 2015

CRM Error: There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.

Hi guys,

Just a quick one.

Just now I receive this error from my triggered custom plugin:

"There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing."

And I believe that this often happen to the development.

Root Cause

Here is the root cause:
1. I have a custom plugin in the onCreate event.

2. Inside my custom plugin, I have Assign function

3. I try to put ‘try and catch’ just to avoid the error

4. Then it hits another error which is: “There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.”

5. So, I put a logger

6. And I have this error, instead:

image

Which this error is actually CRM System Error:
SecLib::CrmCheckPrivilege failed. Returned hr = -2147220943 on UserId: 01dc8c30-eb68-e511-80f2-00155dad0019 and PrivilegeType: Read
So, my conclusion:

Conclusion

1. My Team/User that I want to assign to does not have Any Security Role that having this Read privilege for the entity record object i want to assign to.

2. I try to skip the CRM Error by putting the try and catch just before the ‘Assign’ request

3. But, it fails to proceed, instead, CRM still insists to block this creation..

4. Because it is also right, you cannot do it anyway, CRM system plugin would still block and there is no way you skip the process that needs another rule to apply.

5. Eventhough i put this try catch and try to cancel the Assignment, I still receive the error:

image

What to Check

So, if you find this error, please check:

- Whether you have custom plugin/custom workflow active triggered
- Whether you put skipping the error that will have impact to the CRM process, it is not possible
- Actually you better to log the error
- Because you won’t know what it is
- This is not your logic wrong in your custom plugin
- This just you need to fix why CRM cannot proceed?
- Is that because your user/team does not have privilege or you missed some parameters required
- This error might happen like for Assignment, Lead Qualification, Quote creation, etc

Hope this helps.

Tuesday 6 October 2015

Call Print Preview in CRM and Put in the Web Resource

Sometimes we need summary and as we know, CRM has the Print preview picture, though to call this you need to click the gear setting icon.

So, just in case you want to show the print preview and you want to modify it or add some component, you can put it in the web resource.

And here is the sample code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<!--change this your correct URL can be 
<script src="../../ClientGlobalContext.js.aspx" type="text/javascript"></script>-->
<script>
debugger;

function CallPrintPreview() {
try {

var x = Xrm.Page.ui;

var formId = window.parent.Xrm.Page.ui.formSelector.getCurrentItem().getId();
var recordId = window.parent.Xrm.Page.data.entity.getId();

var objectType = window.parent.Xrm.Page.context.getQueryStringParameters().etc;

var url = Xrm.Page.context.getClientUrl() + "/_forms/print/print.aspx?allsubgridspages=false&formid=" +
formId + "&id=" + recordId + "&objectType=" + objectType;

var iframeSRC = '';
iframeSRC = url;
if (iframeSRC != '') {
document.getElementById("iframePreview").src = iframeSRC;
}
}
catch (e) {

}
}

//YOU CAN ALSO CALL FROM RIBBON AS WELL

//USE THIS FUNCTION IF YOU WANT TO OPEN THE WEB RESOURCE OUTSIDE THE CRM FORM, YOU NEED PARAMETER FROM THE CRM FORM
function CallPrintPreviewByParams(formId, recordId, objectType) {
try {
var url = Xrm.Page.context.getClientUrl() + "/_forms/print/print.aspx?allsubgridspages=false&formid=" +
formId + "&id=" + recordId + "&objectType=" + objectType;

var iframeSRC = '';
iframeSRC = url;
if (iframeSRC != '') {
document.getElementById("iframePreview").src = iframeSRC;
}
}
catch (e) {

}
}

function Submit() {
//put your save button logic here
}

window.onload = CallPrintPreview;

</script>

</head>
<body onload="CallPrintPreview();">
<div id="divIframePrintPreview">
<iframe
id="iframePreview"
src="about:blank"
style="width: 100%; height: 100%; overflow: hidden; border: none; border-width: 0;" frameborder="0"></iframe>
</div>

<!--//you can also add additional in the web resource

<div id="divBody">
<table>
<tr>
<td>Are you sure to submit?</td>
<td></td>
</tr>
<tr>
<td>Remarks:</td>
<td>
<textarea name="comment" form="usrform" style="height: 68px">Enter text here...</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<button value="Submit" title="Submit" name="btnSubmit" type="button" onclick="Submit();">Submit</button>
</td>
</tr>
</table>



</div>-->
</body>
</html>

*I use this as the concept only, you might use your own creative design based on the requirement

So, you can add the remark, for example for the modification or like signature to say ‘OK’ and submit, simple example here:

Launch from the button/put in the form

image


image


image



Hope this helps!

Thanks.