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.

No comments:

Post a Comment

My Name is..