Piata časť zo série Microsoft Dynamics CRM – Javascript API zaoberajúca sa prácou s dialógmi entít – in english as all posts in this category.
These functions are available in every application page that supports scripting. You can use them in form scripts or in ribbon commands. For HTML web resources, they are available when you include the ClientGlobalContext.js.aspx page (full specification you can find on msdn network):
1. Dialogs - There are two types of dialogs: alertDialog and confirmDialog. These are included for use with scripts that will work with Microsoft Dynamics CRM for tablets. CRM for tablets will not allow the use of JavaScript functions that block the flow of code such as window.alert and window.confirm. Use these methods in place of those methods in case you need to display a message to the user. They key difference is that these methods will not block code until a user closes them. They contain a callback function parameter to indicate what code should be executed depending on the user’s response. This method is only available in Update mode.
Xrm.Utility.alertDialog('message', onCloseCallback);
Xrm.Utility.confirmDialog('message', yesCloseCallback, noCloseCallback);
2. Entity Form - Opens an entity form for a new or existing entity record using the options you set as parameters.
Xrm.Utility.openEntityForm(name, id, parameters, windowOptions);
Examples:
Xrm.Utility.openEntityForm("account");
Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");
var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);
var windowOptions = {
openInNewWindow: true
};
Xrm.Utility.openEntityForm("account",null,null,windowOptions);
3. Quick Create Form - For Microsoft Dynamics CRM Online 2015 Update 1 or later use this function to open a new quick create form. You can use this function to set default values using attribute mappings or for specific attributes. If the user saves the record, you can capture a reference to the record created.
Xrm.Utility.openQuickCreate(callback,entityLogicalName,createFromEntity,parameters);
Example:
var thisAccount = {
entityType: "account",
id: Xrm.Page.data.entity.getId()
};
var callback = function (lookup) {
console.log("Created new " + lookup.entityType + " named '" + lookup.name + "' with id:" + lookup.id);
}
var setName = { name: "Child account of "+ Xrm.Page.getAttribute("name").getValue()};
Xrm.Utility.openQuickCreate(callback, "account", thisAccount, setName);
4. Web Resource - Opens an HTML web resource.
Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)
Examples:
Xrm.Utility.openWebResource("new_webResource.htm");
Xrm.Utility.openWebResource("new_webResource.htm", null, 300,300);
var customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value");
Xrm.Utility.openWebResource("new_webResource.htm",customParameters);
Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");