Last week we had new requirement to add Global Close/Cancel Button to all CRM entity to help user go back to previous page in case of current window and if it's new window then close window.
here's steps to do this task :
1- In Ribbon workbench Open solution which has "Application Ribbon" Entity , Add new button "Close/Cancel" with below properties
here's steps to do this task :
1- In Ribbon workbench Open solution which has "Application Ribbon" Entity , Add new button "Close/Cancel" with below properties
2- Create new Command and add javascript action to call javascript function
3- Here's functions to close or go to previous window based on current window or iframe window.
here function checks for "pagemode" param which has "Iframe" value in case of New window
CancelRecord: function () {
var IsNewWindow = getQueryStringParameterValue("pagemode");
if (IsNewWindow == 'iframe') {
window.closeWindow();
window.closeCurrentWindow();
}
else
window.history.back()
}
// Get query string param value
getQueryStringParameterValue: function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "))
}
3- Here's functions to close or go to previous window based on current window or iframe window.
here function checks for "pagemode" param which has "Iframe" value in case of New window
CancelRecord: function () {
var IsNewWindow = getQueryStringParameterValue("pagemode");
if (IsNewWindow == 'iframe') {
window.closeWindow();
window.closeCurrentWindow();
}
else
window.history.back()
}
// Get query string param value
getQueryStringParameterValue: function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "))
}