我需要通过单击任务实体中的按钮打开一个新表单并传递相关内容,我需要指向我从字段“el_task”打开新实体的任务。 关于我weote我工作,但任务部分没有。 我在crm实体表单中创建了参数。 这是我在任务JS文件上写的:
function openElRemarkFormButton() {
var parameters = {};
var Regarding = Xrm.Page.getAttribute("regardingobjectid").getValue();
parameters["parameter_regardingid"] = Regarding[0].id;
parameters["parameter_regardingname"] = Regarding[0].name;
parameters["parameter_regardingtype"] = Regarding[0].entityType;
parameters["parameter_taskName"] = Task.name;
parameters["parameter_taskId"] = Task.id;
//Open the new form
Xrm.Utility.openEntityForm("el_remark", null, parameters);
这是我在el_remark表格上写的:
function OnLoad() {
if (Xrm.Page.ui.getFormType() == 1) {
var param = Xrm.Page.context.getQueryStringParameters();
var regardingId = param["parameter_regardingid"];
var regardingName = param["parameter_regardingname"];
var regardingType = param["parameter_regardingtype"];
var taskName = param["parameter_taskName"];
var taskID = param["parameter_taskId"];
Xrm.Page.getAttribute("el_task").setValue([{ id: taskID, name: taskName }]);
//Populate the Regarding if there is one
if (regardingId != "undefined")
{
Xrm.Page.getAttribute("regardingobjectid").setValue([{ id: regardingId, name: regardingName, entityType: regardingType }]);
答案 0 :(得分:0)
如果el_task
是对任务实体的查找,则在设置时也需要指定entityType
。
Xrm.Page.getAttribute("el_task").setValue([{ id: taskID, name: taskName, entityType: "task" }]);
答案 1 :(得分:0)
这里有几件事。在将id添加到参数数组之前,您需要修复id:
parameters["parameter_regardingid"] = Regarding[0].id.replace(/[{}#]/g, "");
此外,如果您将参数属性命名为与目标表单上的字段名称相同,则无需在onload事件的单独步骤中移动它们。:
parameters["new_fieldnameonTARGETform"] = Xrm.Page.getAttribute("new_fieldnameonTHISform").getValue();
以下是我在调用Xrm.Utility.openEntityForm之前构建参数数组时使用的一些帮助方法。我将这些作为无处不在的Xrm服务工具包的扩展添加,但您可以将它们放在您自己的公共库中。用法如下。
toolkit.AddParameter = function (parameters, attributeName, targetAttributeName) {
/// <summary>
/// Form and add a parameter to the parameters array. Used with Xrm.Utility.openEntityForm.
/// Example: XrmServiceToolkit.Common.addParameter(parameters, "new_firstname");
/// <param name="parameters" type="array">
/// The parameter object array, i.e. var parameters = {};
/// </param>
/// <param name="attributeName" type="string">
/// The name of the field on the source form.
/// </param>
/// <param name="targetAttributeName" type="string" optional="true">
/// The name of the field on the target form; not required of the source and target
/// field names are identical.
/// </param>
/// </summary>
var attribute = Xrm.Page.getAttribute(attributeName);
if (!toolkit.IsNullOrEmpty(attribute)) {
if (!toolkit.IsNullOrEmpty(attribute.getValue())) {
parameters[(arguments.length == 3 ? targetAttributeName : attributeName)] = attribute.getValue();
}
}
};
toolkit.AddDateParameter = function (parameters, attributeName, targetAttributeName)
{
/// <summary>
/// Form and add a date parameter to the parameters array. Used with Xrm.Utility.openEntityForm.
/// Example: XrmServiceToolkit.Common.addDateParameter(parameters, "new_birthdate", "new_dateofbirth");
/// <param name="parameters" type="array">
/// The parameter object array, i.e. var parameters = {};
/// </param>
/// <param name="attributeName" type="string">
/// The name of the field on the source form.
/// </param>
/// <param name="targetAttributeName" type="string" optional="true">
/// The name of the field on the target form; not required of the source and target
/// field names are identical.
/// </param>
/// </summary>
var attribute = Xrm.Page.getAttribute(attributeName);
if (!toolkit.IsNullOrEmpty(attribute)) {
if (!toolkit.IsNullOrEmpty(attribute.getValue())) {
var dateValue = attribute.getValue();
parameters[(arguments.length == 3 ? targetAttributeName : attributeName)] = dateValue.getMonth() + '/' + dateValue.getDate() + '/' + dateValue.getFullYear();
}
}
};
toolkit.AddLookupParameter = function (parameters, attributeName, targetAttributeName) {
/// <summary>
/// Form and add a lookup parameter to the parameters array. Used with Xrm.Utility.openEntityForm.
/// Example: XrmServiceToolkit.Common.addLookupParameter(parameters, "new_consumerid");
/// <param name="parameters" type="array">
/// The parameter object array, i.e. var parameters = {};
/// </param>
/// <param name="attributeName" type="string">
/// The name of the field on the source form.
/// </param>
/// <param name="targetAttributeName" type="string" optional="true">
/// The name of the field on the target form; not required of the source and target
/// field names are identical.
/// </param>
/// </summary>
var attribute = Xrm.Page.getAttribute(attributeName);
if (!toolkit.IsNullOrEmpty(attribute)) {
if (!toolkit.IsNullOrEmpty(attribute.getValue())) {
parameters[(arguments.length == 3 ? targetAttributeName : attributeName)] = attribute.getValue()[0].id.replace(/[{}#]/g, "");
parameters[(arguments.length == 3 ? targetAttributeName : attributeName) + "name"] = attribute.getValue()[0].name;
}
}
};
用法是:
//argument of the openEntityForm().
var parameters = {};
//add values to the parameter array.
XrmServiceToolkit.Common.AddLookupParameter(parameters, "new_opportunityid");
XrmServiceToolkit.Common.AddParameter(parameters, "new_status");
XrmServiceToolkit.Common.AddDateParameter(parameters, "new_startdate");
//open the editor page for this entity type.
Xrm.Utility.openEntityForm("new_entity", null, parameters);