从相同的网格创建 Window
Create From Grid in Same Window
我正在尝试更新网格上的“添加新按钮”以在当前 window 中打开,而不是在新按钮中打开。我已经编辑了功能区 XML,并且在单击“+”图标时正确地调用了此函数:
export function createCase(selectedEntityTypeCode: number, parentEntityTypeCode: number, firstPrimaryItemId: string, primaryControl: string, selectedControl: string): void {
window.top.location.replace(CommonLib.getCreateEntityFromParentUrl(firstPrimaryItemId, parentEntityTypeCode, selectedEntityTypeCode));
}
对 getCreateEntityFromParentUrl 的调用创建了这个字符串:
etc=112&extraqs=%3f_CreateFromId%3d%257b999BA23A-B07A-E611-80DD-FC15B4286CB8 %257d%26_CreateFromType%3d10010%26etc%3d112&newWindow=false&pagetype= entityrecord
这会打开一个新的 Case 表单,其中已经填充了正确的 Parent 实体,所以我知道它正在正确地从 CreateFromID 和 CreateFromType 中读取。
如果您实际上没有创建案例,而是在浏览器中单击刷新,您将返回到父实体(在本例中为自定义实体,"Location")。
如果您保存创建案例,然后在浏览器中单击刷新,您会收到此错误:
Unhandled Exception:
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault,
Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException:
Microsoft Dynamics CRM has experienced an error. Reference number for
administrators or support: #5B02AEE3Detail:
-2147220970 System.Web.HttpUnhandledException: Microsoft Dynamics
CRM has experienced an error. Reference number for administrators or
support: #5B02AEE3
2016-09-15T04:30:58.0199249Z
-2147220969
allgnt_location With Id = 3e10a729-fd7a-e611-80dd-fc15b4286cb8 Does Not Exist
2016-09-15T04:30:58.0199249Z
如果您从该实体创建一个 phone 调用,并单击命令栏中的“完成调用”按钮,您也会收到此错误。
列出的 ID 是案例的 ID,但显然,CRM 试图将其加载为 Location,这显然失败了。我做错了吗?
感谢@Polshgiant 让我走上正轨。我需要打电话给 Xrm.Utility.openEntityForm。这个 Typescript 函数对我有用!
/**
* Opens a create form for a child entity of a parent. Useful if a subgrid add new button should redirect to the new page, rather than the default open in a new window.
* @param parentEntityId Id of the parent entity
* @param parentEntityTypeCode Object Type Code of the parent Entity
* @param childLogicalName Child Logical Name
* @param parameters Object whos properties will be added to the extraQs parameters
*/
export function openCreateChildFormInCurrentWindow(parentEntityId: string, parentEntityTypeCode: number, childLogicalName: string, parameters?: any) {
const params = {
formid: null,
["_CreateFromId"]: parentEntityId,
["_CreateFromType"]: parentEntityTypeCode.toString()
} as Xrm.Utility.FormOpenParameters;
if (parameters) {
for (const param in parameters) {
if (parameters.hasOwnProperty(param)) {
params[param] = parameters[param];
}
}
}
Xrm.Utility.openEntityForm(childLogicalName, null, params, { openInNewWindow: false } as Xrm.Utility.WindowOptions);
}
我正在尝试更新网格上的“添加新按钮”以在当前 window 中打开,而不是在新按钮中打开。我已经编辑了功能区 XML,并且在单击“+”图标时正确地调用了此函数:
export function createCase(selectedEntityTypeCode: number, parentEntityTypeCode: number, firstPrimaryItemId: string, primaryControl: string, selectedControl: string): void {
window.top.location.replace(CommonLib.getCreateEntityFromParentUrl(firstPrimaryItemId, parentEntityTypeCode, selectedEntityTypeCode));
}
对 getCreateEntityFromParentUrl 的调用创建了这个字符串:
etc=112&extraqs=%3f_CreateFromId%3d%257b999BA23A-B07A-E611-80DD-FC15B4286CB8 %257d%26_CreateFromType%3d10010%26etc%3d112&newWindow=false&pagetype= entityrecord
这会打开一个新的 Case 表单,其中已经填充了正确的 Parent 实体,所以我知道它正在正确地从 CreateFromID 和 CreateFromType 中读取。
如果您实际上没有创建案例,而是在浏览器中单击刷新,您将返回到父实体(在本例中为自定义实体,"Location")。
如果您保存创建案例,然后在浏览器中单击刷新,您会收到此错误:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #5B02AEE3Detail:
-2147220970 System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #5B02AEE3
2016-09-15T04:30:58.0199249Z -2147220969 allgnt_location With Id = 3e10a729-fd7a-e611-80dd-fc15b4286cb8 Does Not Exist 2016-09-15T04:30:58.0199249Z
如果您从该实体创建一个 phone 调用,并单击命令栏中的“完成调用”按钮,您也会收到此错误。
列出的 ID 是案例的 ID,但显然,CRM 试图将其加载为 Location,这显然失败了。我做错了吗?
感谢@Polshgiant 让我走上正轨。我需要打电话给 Xrm.Utility.openEntityForm。这个 Typescript 函数对我有用!
/**
* Opens a create form for a child entity of a parent. Useful if a subgrid add new button should redirect to the new page, rather than the default open in a new window.
* @param parentEntityId Id of the parent entity
* @param parentEntityTypeCode Object Type Code of the parent Entity
* @param childLogicalName Child Logical Name
* @param parameters Object whos properties will be added to the extraQs parameters
*/
export function openCreateChildFormInCurrentWindow(parentEntityId: string, parentEntityTypeCode: number, childLogicalName: string, parameters?: any) {
const params = {
formid: null,
["_CreateFromId"]: parentEntityId,
["_CreateFromType"]: parentEntityTypeCode.toString()
} as Xrm.Utility.FormOpenParameters;
if (parameters) {
for (const param in parameters) {
if (parameters.hasOwnProperty(param)) {
params[param] = parameters[param];
}
}
}
Xrm.Utility.openEntityForm(childLogicalName, null, params, { openInNewWindow: false } as Xrm.Utility.WindowOptions);
}