0

我有一个问题,我真的想弄清楚如何最好地解决这个问题。我已经阅读了有关此错误的各种帖子,并且您似乎可以通过使用 JavaScript 来避免这种情况:

Xrm.Page.getAttribute("name").setSubmitMode("always");

这对我或插件内部不起作用。现在我的问题是,我的事件表单上有一个更新插件触发,它更新了一些字段。但是,当我尝试解决此案例或取消它时,我从更新插件中收到错误“该对象无法更新,因为它是只读的”我尝试了以下操作,如果有人能告诉我我在做什么,我将不胜感激错误的。我在针对事件表单进行预操作时注册为 SetState 的插件代码:

SetStateRequest setState = new SetStateRequest(); 
setState.EntityMoniker = new EntityReference(); 
setState.EntityMoniker.Id = incidentId; //Id which needs to be resolved/canceld 
setState.EntityMoniker.Name = "statecode"; 
setState.EntityMoniker.LogicalName = "incident"; 
setState.State = new OptionSetValue(); 
setState.Status = new OptionSetValue(); 
 SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState); } 

关于状态和状态,我很困惑我必须将其设置为什么值。当我的事件处于活动状态并且我正在尝试解决并取消该案例时,我只是收到了一个错误。如果有人可以在这里帮助我,我将不胜感激。提前致谢。

4

2 回答 2

4

I think there are a few areas of confusion in your post...

Xrm.Page.getAttribute("name").setSubmitMode("always");

This is clientside code and will never have any bearing on the behaviour of your (serverside) plugin. It merely forces an attribute on the form to be submitted whether it has changed or not, during a save. If the record is in a read-only state, it will not change that fact.

I'm not at all clear what you are trying to acheive in your code. You mention that an update plugin is failing; you have posted code which would attempt to set the state of the incident to something (as @glosrob suggests, you are not providing any values in the OptionSetValue objects for State and Status so as you might already know, the code you have posted is invalid); you then state that you have registered your plugin on the SetState request. This means that it would fire if the user tries to set the state of the incident. Given that your code is itself trying to set the status of the incident, I'm not sure that it makes sense...

It sounds like what you want to do is, on update of an incident, set certain values. If the incident is in a read-only state, make it readable first, and then update the values. Do you then need to restore the state of the entity to it's former state? It sounds awkward and might perhaps suggest that there is a better way to meet your core requirement.

Maybe start with what you are trying to achieve and we can work from there :)

于 2012-05-17T15:39:34.683 回答
3

你应该删除

setState.EntityMoniker.Name = "statecode";

从你的代码。该字段Name有其他用途。

另外,您应该添加

setState.State.Value = 1;
setState.Status.Value = -1;
于 2012-05-18T06:31:51.317 回答