我正在尝试更新网格上的“添加新”按钮以在当前窗口中打开,而不是新窗口。我编辑了功能区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。
如果您实际上没有创建案例,并在浏览器中单击刷新,则会被带回父实体(在这种情况下为自定义实体,“位置”)。
如果保存创建案例,然后在浏览器中单击“刷新”,则会出现此错误:
未处理的例外情况: 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遇到错误。参考编号 管理员或支持:#5B02AEE3Detail:
-2147220970 System.Web.HttpUnhandledException:Microsoft Dynamics CRM遇到了错误。管理员或参考号 支持:#5B02AEE3
2016-09-15T04:30:58.0199249Z -2147220969 具有Id = 3e10a729-fd7a-e611-80dd-fc15b4286cb8的allgnt_location不存在 2016-09-15T04:30:58.0199249Z
如果您从此实体创建了一个电话,并且单击命令栏中的“完成呼叫”按钮,也会出现此错误。
列出的Id是案例的ID,但显然,CRM正在尝试将其作为位置加载,这显然是失败的。我做错了吗?
答案 0 :(得分:2)
感谢@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);
}