为了使用数据填充自定义屏幕,您需要将数据传递到屏幕。
首先,您需要获取 Id 值。在这种情况下,我们从 URL 获取它:
var CommId = Request.QueryString("Key6") + '';
不过,我们将进行一些其他检查。这些主要是为了处理不同版本或不同用户操作中出现的场景。
// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
CommId = 0;
} else if(CommId.indexOf(",") > -1){
CommId = CommId.substr(0,CommId.indexOf(","));
}
某些用户操作可以使 URL 在同一属性中包含多个 Id。在这些情况下,这些 ID 用逗号分隔。因此,如果未定义 Id,我们检查其中是否有逗号。如果有,我们取第一个 ID。
得到Id后,我们需要加载记录。此时,您应该已经检查了您有一个有效的 id(例如不为零)并进行了一些错误处理。在某些页面中您可能想要显示错误,在其他页面中您可能想要创建一个新的空白记录。这得到了记录:
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);
之后,您需要将记录应用到屏幕上。使用上面的示例:
CustomCommunicationDetailBox.ArgObj = CommRecord;
将所有这些添加到您的脚本中,您会得到:
var CommId = Request.QueryString("Key6") + '';
// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
CommId = 0;
} else if(CommId.indexOf(",") > -1){
CommId = CommId.substr(0,CommId.indexOf(","));
}
// add some error checking here
// get the communication record
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);
// get the container and the detail box
var Container = CRM.GetBlock("Container");
var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");
// apply the communication record to the detail box
CustomCommunicationDetailBox.ArgObj = CommRecord;
// add the box to the container
Container.AddBlock(CustomCommunicationDetailBox);
// set the moder
if(!Defined(Request.Form)){
CRM.Mode=Edit;
} else {
CRM.Mode=Save;
}
// output
CRM.AddContent(Container.Execute());
var sHTML=CRM.GetPageNoFrameset();
Response.Write(sHTML);
但是,我们建议您进行更多的错误/异常处理。如果用户正在保存记录,您还需要在页面写入后添加重定向。
六点支持