简体   繁体   English

在Dynamics CRM Opportunity中进行“初始保存”后,值似乎会立即改变

[英]Values seems changing straight after Initial Save in Dynamics CRM Opportunity

I'm doing a Service Call to retrieve the Account details (currency, discount associated with the account) on the Selection of the Account lookup on the Opportunity form (form type == 1 // Create) using Web API in CRM 2016 On-Premise . 我正在进行服务调用,以使用CRM 2016 On-上的 Web API在“机会”表单(表单类型== 1 //创建)上选择“帐户”查找时检索“帐户详细信息”(货币,与该帐户相关的折扣)。 前提 Everything is working fine but when the opportunity is saved initially it's straight away coming up with unsaved changes next to the Save button after the initial save which is forcing me to do another save(abnormal behaviour).I'm not so sure what value is changing straightaway after initial save. 一切工作正常,但最初保存机会时,立即保存后立即出现未保存的更改 ,这会迫使我再次进行保存(异常行为),这迫使我再次进行保存(异常行为)。初始保存后立即更改。

The Service Call is Synchronous and is being triggered on the change of the Account Lookup, well before the initial save. 服务呼叫是同步的,并且在更改帐户查找时被触发,并且早于初始保存。 Any Help Appreciated!. 任何帮助表示赞赏!。

function SetOpportunityCurrencyAndDiscount(){
    var accountId = (GetValue("vm_accountid"))[0].id;
    var result = RetrieveRecord("account", null, accountId.slice(1,-1));
    var accountDiscount = result["vm_accountdiscount"];
    var transactionCurrencyId = result["_transactioncurrencyid_value"];
    var currencyName =  result["_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue"];
    SetValue("vm_discount", accountDiscount);
    Xrm.Page.getAttribute("transactioncurrencyid").setValue([{ id: transactionCurrencyId, name: currencyName, entityType: "transactioncurrency"}]); }

function RetrieveRecord(recordType, alternateKey, accountId){
    var result = null;
    var entityType = recordType;
    var query = null;
    if(alternateKey != null && agencyId == null)
        query = "/api/data/v8.0/accounts(emailaddress1='"+alternateKey+"')?$select=name,accountid,_transactioncurrencyid_value,vm_agencydiscount";
    else
        query = "/api/data/v8.0/accounts("+agencyId+")?$select=name,accountid,_transactioncurrencyid_value,vm_agencydiscount";
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + query, false);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                result = JSON.parse(this.response);
            }
            else {
                alert(this.statusText);
            }
        }
    };
    req.send();
    return result; 
}

After you save your record and the form is dirty again, open dev tools and paste this into the console. 保存记录并再次使表单变脏后,打开开发工具并将其粘贴到控制台中。 It will show you which fields are dirty. 它会告诉您哪些字段是脏的。

function showDirtyFields() { 
    var Xrm = Array.prototype.slice.call(document.querySelectorAll('iframe')).filter(function(d) {
        return d.style.visibility !== 'hidden';
    })[0].contentWindow.Xrm;
    var message='The following fields are dirty: \n';
    Xrm.Page.data.entity.attributes.forEach(function(attribute,index){
        if(attribute.getIsDirty()==true){message+="\u2219 "+attribute.getName()+"\n";}
    });
    Xrm.Utility.alertDialog(message);
}
showDirtyFields();

Another way of accomplishing the same thing is to turn on auditing for the entity. 完成同一件事的另一种方法是打开实体的审核。 The audit log will show you which fields were submitted. 审核日志将显示您提交了哪些字段。

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

相关问题 如何设置机会状态-Dynamics CRM? - How to set the Opportunity Status - Dynamics CRM? 为什么此代码不会在Microsoft Dynamics CRM 2011中使用Odata创建机会? - Why will this code not create an Opportunity using Odata in Microsoft Dynamics CRM 2011? 无法使用估算的关闭日期对Dynamics CRM“机会”交易类型执行过滤 - Not able to perform Filter on Dynamics CRM “Opportunity” transaction type with estimatedclosedate 图表和视图中未反映正在改变机会的销售阶段-CRM Online 9.0 - Changing sales stage on Opportunity is not reflected in charts and views - CRM Online 9.0 动态 crm + 插件逻辑更新零值 - Dynamics crm + plugin logic to update zero values 是否可以在没有 SDK 的情况下调用 Dynamics CRM 2011 后期绑定 WCF 组织服务 - 直接自定义绑定? - Is it possible to call Dynamics CRM 2011 late-bound WCF Organization service without the SDK - straight customized binding? 将Dynamics CRM 2011表单保存在Silverlight浏览器组件中 - Save a Dynamics CRM 2011 form inside a Silverlight browser component 在Dynamics CRM中添加部分图标并更改背景颜色 - Adding section icons and changing background color in dynamics CRM Dynamics CRM 2011 - 更改相关实体列表的视图 - Dynamics CRM 2011 - Changing the view for a related entity list MS CRM 2013-机会产品 - MS CRM 2013 - Opportunity Product
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM