2016-09-15 37 views
2

我正在嘗試更新網格上的添加新按鈕以在當前窗口中打開,而不是新建一個新窗口。我已經編輯功能區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中讀取。

如果您沒有實際創建案例,並在瀏覽器中單擊刷新,則會將其帶回父實體(本例中爲自定義實體「位置」)。

如果您保存創建的情況下,然後單擊瀏覽器刷新,你得到這個錯誤:

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

,如果你創建這個實體的電話也收到此錯誤,並單擊完成在命令欄中調用按鈕。

Id列出的是Case的id,但很顯然,CRM試圖將它作爲Location來加載,這顯然是失敗的。我做錯了嗎?

+0

也許嘗試使用[Xrm.Utility.openEntityForm(https://msdn.microsoft.com/en-us/library/jj602956.aspx?f=255&MSPPError=-2147217396#BKMK_OpenEntityForm)?文檔暗示它默認在當前窗口中打開,但您必須手動生成CreateFromID和CreateFromType。 – Polshgiant

回答

1

感謝@Polshgiant讓我開始走下正軌。我需要調用Xrm.Utility.openEntityForm。這個手稿功能適合我!

/** 
* 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); 
}