原文地址:https://github.com/PaulNieuwelaar/alertjs/wiki/Documentation#alertshow
Use this method to show a light-box message. This can be called from a form, view, or anywhere that supports JavaScript. As of version 2.0, the unsupported CRM light-box is no longer being used. Instead a custom dialog is displayed, 100% contained within the solution, meaning the lightbox displays seamlessly on any browser.
Alert.show(title, message, buttons, icon, width, height, baseUrl, preventCancel, padding)
title
"Would you like to create a sale?"
message
"This will create and open the new sale record."
buttons
[
new Alert.Button("Create Sale", createSaleFunction, true),
new Alert.Button("Not now")
]
new Alert.Button(label, callback, setFocus, preventClose)
icon
"QUESTION"
width
500
height
250
baseUrl
Xrm.Page.context.getClientUrl()
. Must be specified where Xrm.Page is not available, e.g. from web resources."http://server/org"
preventCancel
true
padding
30
Use this method to manually hide the alert from code. This is useful if you have a background process running which once completed, will automatically close the alert. This function accepts no input parameters, and has no return type. This will simply hide any alert being displayed at the time.
Alert.hide()
Use this method to display a small loading spinner with the text "Loading...". This is just a simple wrapper for the Alert.show method with a few standardised defaults, making it easier to reuse when needing to display a loading message.
Alert.showLoading(url)
url
Xrm.Page.context.getClientUrl()
. Must be specified where Xrm.Page is not available, e.g. from web resources."http://server/org"
Use this method to display an HTML web resource inside a light-box. The URL of the web resource is generated and then passed into the Alert.showIFrame function, which creates an iframe to the web resource. You can also optionally add custom titles, buttons, and padding, just like the standard Alert.show function.
Alert.showWebResource(webResourceName, width, height, title, buttons, baseUrl, preventCancel, padding)
To access the web resource document, i.e. to get the values from inputs on the web resource, you can make a call to Alert.getIFrameWindow from the button callback of this alert, or from any other JavaScript. This allows you to access any elements inside the web resource being displayed.
To access CRM components from inside the web resource document, i.e. to execute some other form logic on click of a button inside your web resource, you can make a call to Alert.getCrmWindow from anywhere inside the web resource. This allows you to call other functions, or access form fields directly from within the web resource.
webResourceName
"new_/html/tester.html?Data=" + encodeURIComponent("someVar1=1&someVar2=2")
width
1600
height
900
title
"Change Account Name"
buttons
[new Alert.Button("OK", doSomething)]
baseUrl
Xrm.Page.context.getClientUrl()
. Must be specified where Xrm.Page is not available, e.g. from web resources."http://server/org"
preventCancel
true
padding
30
Use this method to display a CRM dialog process inside a light-box. The URL of the dialog process is generated and then passed into the Alert.showIFrame function, which creates an iframe to the dialog process. You can also optionally specify a callback function which will execute when the dialog is completed or cancelled, allowing you to refresh the form for example.
Alert.showDialogProcess(dialogId, entityName, recordId, callback, width, height, baseUrl)
dialogId
"ac03c16e-40b2-41c4-9831-4f651b77f393"
entityName
"account"
recordId
Xrm.Page.data.entity.getId()
.Xrm.Page.data.entity.getId()
callback
function () {
Xrm.Page.data.refresh();
}
width
1600
height
900
baseUrl
Xrm.Page.context.getClientUrl()
. Must be specified where Xrm.Page is not available, e.g. from web resources."http://server/org"
Use this method to display a URL inside a light-box, via an iFrame. You can also optionally add custom titles, buttons, and padding, just like the standard Alert.show function.
Alert.showIFrame(iframeUrl, width, height, title, buttons, baseUrl, preventCancel, padding)
To access the iframe document, i.e. to get the values from inputs on the web page, you can make a call to Alert.getIFrameWindow from the button callback of this alert, or from any other JavaScript. This allows you to access any elements inside the web page being displayed. Note that cross-domain scripting is not allowed, so the web page being displayed in the iframe must be on the same domain as CRM for you to access its document via this method.
To access CRM components from inside the iframe document, i.e. to execute some other form logic on click of a button inside your web page, you can make a call to Alert.getCrmWindow from anywhere inside the web page. This allows you to call other functions, or access form fields directly from within the iframe document. Note that cross-domain scripting is not allowed, so the web page being displayed in the iframe must be on the same domain as CRM for you to call into CRM from its document.
iframeUrl
"http://bing.com"
works but "http://google.com"
does not."http://bing.com"
width
1600
height
900
title
"Change Account Name"
buttons Type: Array of Alert.Button objects. The buttons to display at the bottom of the iframe. If this is set to null, no buttons will be displayed (i.e. if the buttons are managed inside the iframe). See the Alert.show documentation above for how to structure the buttons. To access values from the iframe, make a call to Alert.getIFrameWindow from the button callback.
[new Alert.Button("OK", doSomething)]
baseUrl
Xrm.Page.context.getClientUrl()
. Must be specified where Xrm.Page is not available, e.g. from web resources."http://server/org"
preventCancel
true
padding
30
Use this method to get the context of an iFrame being displayed in the light-box. For example, if you‘re capturing input via a web resource, you can use this function to access the inputs on the web resource from inside a custom function. This allows you to use custom buttons to access the iFrame data.
Alert.getIFrameWindow()
var iFrameWindow = Alert.getIFrameWindow();
var value = iFrameWindow.document.getElementById("somefield").value;
This method gives you context of the CRM form (or client API wrapper if turbo forms are enabled). This allows you to access CRM functions, and your own custom JavaScript libraries from inside iFrame alerts. From inside a web resource, for example, you can call parent.Alert.getCrmWindow().doSomething();
, where "doSomething()" represents a custom function loaded onto the parent form.
Alert.getCrmWindow()
var crmWindow = parent.Alert.getCrmWindow();
crmWindow.Xrm.Page.getAttribute("name").setValue("something")
Use this method to encode a custom message which contains HTML characters, to allow it to be displayed inside the alert message. For example, if displaying formatted XML with indented spacing and XML tags, calling this method will format the text into an HTML friendly message that displays nicely inside the alert. The returned value should then be passed to the ‘message‘ of the Alert.show method.
NOTE: If you want to actually use HTML tags, like <b>bold</b>, you should not use this method.
Alert.htmlEncode(text)
text
" <InnerFault>\n" +
" <ErrorCode>-2147220969</ErrorCode>\n" +
" <ErrorDetails xmlns:d3p1=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />\n" +
" <Message>account With Id = b966e678-1d9d-e011-9293-000c2981699a Does Not Exist</Message>\n" +
" <Timestamp>2016-06-22T04:13:14.4579317Z</Timestamp>\n" +
" <InnerFault i:nil=\"true\" />\n" +
" <TraceText i:nil=\"true\" />\n" +
" </InnerFault>"
" <InnerFault><br /> <ErrorCode>-2147220969</ErrorCode><br /> <ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /><br /> <Message>account With Id = b966e678-1d9d-e011-9293-000c2981699a Does Not Exist</Message><br /> <Timestamp>2016-06-22T04:13:14.4579317Z</Timestamp><br /> <InnerFault i:nil="true" /><br /> <TraceText i:nil="true" /><br /> </InnerFault>"
原文:https://www.cnblogs.com/BinBinGo/p/9929120.html