簡體   English   中英

在 Dynamics 365 中輸入字段變臟時自動保存表單

[英]Autosaving a form when an input field gets dirty in Dynamics 365

這個腳本有什么問題? 我收到此錯誤 -腳本錯誤 - 此記錄的腳本之一導致了錯誤。 有關詳細信息,請下載日志文件。

function autosaveWhenFieldIsDirty(formContext)
{
    var isFieldDirty = formContext.getAttribute("logdate").getIsDirty();

    var saveOptions = {
        saveMode: 70
    };

    if(isFieldDirty == true)
    {
        formContext.data.save(saveOptions).then(
            function (success) {
                console.log(success);
            },
            function (error) {
                console.log(error);
            }
        );
    }
}

我相信您腳本的主要問題與參數有關。 當 function 綁定到 onchange 事件時,executionContext 在處理程序中傳遞,而不是 formContext,因此您應該嘗試使用以下代碼:

function autosaveWhenFieldIsDirty(executionContext) {
var formContext = executionContext.getFormContext();

var isFieldDirty = formContext.getAttribute("logdate").getIsDirty();

var saveOptions = {
    saveMode: 70
};

if (isFieldDirty == true) {
    formContext.data.save(saveOptions).then(
        function(success) {
            console.log(success);
        },
        function(error) {
            console.log(error);
        }
    );
}

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM