当为从功能区打开的表单调试CRM 2011中的javascript时,为什么会创建脚本块? [英] How come when debugging javascript in CRM 2011 for a form opened up from the ribbon, script blocks are created?

查看:73
本文介绍了当为从功能区打开的表单调试CRM 2011中的javascript时,为什么会创建脚本块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向现场CRM 2011中的自定义实体添加约会。

I'm adding an appointment to a custom entity in an on site CRM 2011.


  • 我单击功能区上的新建活动按钮,选择约会,然后单击确定。

  • 在打开的新窗口中,我F12打开IE调试器,然后选择脚本选项卡,在我的onLoad函数和FormScript.js.aspx文件的crmForm_window_onload_handler中都设置一个断点,然后单击开始调试按钮。

  • I然后重新加载约会窗口。

crmForm_window_onload_handler中的断点命中,但是当我进入自定义js网络资源文件(appointment.js)的onLoad函数时,而不是进入我的pointing.js文件的onLoad函数时,它将进入的确切副本的onLoad我的文件,唯一的名字是脚本块(0-99之间的某个随机数),即 script block(23)。为什么要创建这些脚本块?在保存中,我还运行以下代码:

The break point in crmForm_window_onload_handler hits, but when I step into what should be the onLoad function of my custom js web resource file (appointment.js), rather than stepping into the onLoad function of my appointment.js file, it steps into the onLoad of an exact copy of my file, only it's name is script block (some random number from 0-99) ie script block(23). Why are these script blocks being created? In the on Save I'm also running this code:

Xrm.Page.getAttribute('new_issyncreqd').setValue(true);
Xrm.Page.getAttribute('new_issyncreqd').setSubmitMode("always");

但是它实际上并没有保存,我想它与脚本块有关...

But it's not actually saving and I'm guessing it's related to the script blocks...

我确实弄清楚了为什么要更新的代码IsSyncReqrdField不起作用。这适用于Site CRM 2011版本V 5.0.9690.1992(汇总6)。显然,约会实体存在一个错误,先保存该实体,然后实际运行自定义onSave代码。当前是这样的:

I did figure out why the code that is updating the IsSyncReqrdField is not working. This is for on Site CRM 2011 version V 5.0.9690.1992 (rollup 6). It apparently has a bug for the Appointment entity where it saves the entity first, then actually runs the custom onSave code. This is how it currently looks:

function crmForm_onsave_handler(eventObj,eventArgs)
{
  try
  {
    var eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,eventArgs,null);
    eContext = Mscrm.FormUtility.constructExecutionObject(eventObj,0,eventArgs,eContext)
    Mscrm.Form_onsave();
    eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,1,eventArgs,eContext)
    NEW.Appointment.onSave(eContext); // <-- My custom OnSave Handler 
  }
  catch(e)
  {
    displayError('crmForm', 'onsave', e.description);
  }
}

错误是 Mscrm.Form_onsave(); 行实际上是将记录保存到数据库中,因此,在运行自定义事件处理程序时,该记录已保存,并且在自定义事件处理程序中进行的任何更新都不会更新该记录。记录。

The bug is that the Mscrm.Form_onsave(); line is actually saving the record to the database, so when the custom event handler runs, it's already been saved, and any updates made in the custom event handler won't update the record.

此错误的解决方法是在窗体的onLoad中将 bSaveInProgress = true; 设置为然后
bSaveInProgress =!isValid;
event.returnValue = isValid; $ on $中的
bSaveInProgress = true; 会保留 Mscrm.Form_onsave(); 实际保存recrod和event.returnValue实际上导致它被创建。它可以工作并且是一个hack,但是这是我想出的唯一解决此错误的方法...

The fix for this bug is to set bSaveInProgress = true; in the onLoad of the form, and then bSaveInProgress = !isValid; event.returnValue = isValid; in the onSave. The bSaveInProgress = true; will keep Mscrm.Form_onsave(); from actually saving the recrod and the event.returnValue will actually cause it to be created. It works and is a hack, but it's the only thing I've come up with to work around this bug...

为什么要创建和执行脚本块而不是使用已经存在的文件?

Why are script blocks being created and executed instead of using the file that is already there?

推荐答案

首先,当内联javascript来自XML或SVG文件时,将创建脚本块。

First, script blocks are created when inline javascript is coming from an XML or SVG file.

这是一个已知的IE问题(扫描脚本块): http://msdn.microsoft.com/en-us/ie/ff959805.aspx

This is a known IE issue (scan for "script block"): http://msdn.microsoft.com/en-us/ie/ff959805.aspx

您可以使用IE9中的网络标签查看XML文件,然后捕获表单加载。应该有一些实际上是XML的aspx文件。一个示例是RenderGridView.aspx。

You can see the XML files, by usingthe "Network" tab in IE9 and then capturing a form load. There should be a few aspx files that are actually XML. An example is RenderGridView.aspx.

因此,问题在于再次检索了aspx文件,然后执行内联函数替换了先前的脚本块(因为javascript以单个全局文件)。

So the problem is that the aspx file is being retrieved again and then executing the inline function replacing the former script block (since javascript operates as a single global file).

这篇关于当为从功能区打开的表单调试CRM 2011中的javascript时,为什么会创建脚本块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆