简体   繁体   English

Dynamics CRM 2015-通过javascript更新商机所有者ID

[英]Dynamics CRM 2015 - update Opportunity Owner id via javascript

I'm trying to update the OwnerId on an opportunity in Dynamics CRM 2015. 我正在尝试在Dynamics CRM 2015中更新机会的OwnerId。

So far I am using the following code but my changes are not taking effect. 到目前为止,我正在使用以下代码,但是我的更改没有生效。

Xrm.Page.data.entity.attributes.get('ownerid').setValue('487ecd0c-d8c1-e411-80eb-c4346bade4b0')
Xrm.Page.data.entity.save();

This is a view of the GetValue call. 这是GetValue调用的视图。

在此处输入图片说明

The attribute type is "lookup" and when I call getIsDirty(), it returns false after I do setValue, so I'm not sure if that's the correct way to set the value on a "lookup" type. 属性类型是“ lookup”,当我调用getIsDirty()时,在执行setValue后它会返回false,因此我不确定这是否是在“ lookup”类型上设置值的正确方法。

Owner is a special field, it can be changed only with an AssignRequest . Owner是一个特殊字段,只能使用AssignRequest进行更改。

With CRM Online Update 1 this changed, special fields like Owner or StateCode can be updated with an update request, but as far as I know this is valid from server side, for client side changes you will still need to use an AssignRequest . 使用CRM Online Update 1进行此更改后,可以使用更新请求来更新诸如OwnerStateCode类的特殊字段,但是据我所知,这在服务器端有效,对于客户端更改,您仍然需要使用AssignRequest

Here a sample code: 这里是一个示例代码:

Using Assign Requests to Assign Entities to a User Using Jscript and .NET in Microsoft Dynamics CRM 2011 在Microsoft Dynamics CRM 2011中使用分配请求将实体分配给使用Jscript和.NET的用户

EDIT: Just for reference, this is the way to set a lookup field 编辑:仅供参考,这是设置查找字段的方法

var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = '{487ecd0c-d8c1-e411-80eb-c4346bade4b0}';
lookup[0].name = 'Test Account';
lookup[0].entityType = 'account';
Xrm.Page.getAttribute("new_account").setValue(lookup);

or short version 或短版

Xrm.Page.getAttribute("new_account").setValue([{ id: '{487ecd0c-d8c1-e411-80eb-c4346bade4b0}', name: 'Test Account', entityType: 'account'}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM