【问题标题】:How to Clone an custom entity in dynamics 365 using javaScript如何使用 javaScript 在 Dynamics 365 中克隆自定义实体
【发布时间】:2021-01-13 13:36:04
【问题描述】:

我遇到了一个我必须克隆我的自定义实体的场景。 然后我通过在触发我的 JavaScript 的功能区中放置一个自定义重复按钮开始使用 JavaScript。

我使用了以下代码:

function duplicateOrder(primaryControl){
var formContext = primaryControl;
var city = formContext.getAttribute('new_city').getValue();
var country = formContext.getAttribute('new_country').getValue();
var state = formContext.getAttribute('new_state').getValue();
var postal_code = formContext.getAttribute('new_zipcodepostalcode').getValue();

// var formItem = formContext.ui.formSelector.items.get();
// alert(`the form item value is ${formItem}`);
formContext.data.entity.save('saveandnew');

sleep(3000);
var city1 = formContext.getAttribute('new_city').getValue();
var country1 = formContext.getAttribute('new_country').getValue();
var state1 = formContext.getAttribute('new_state').getValue();
var postal_code1 = formContext.getAttribute('new_zipcodepostalcode').getValue();

alert(`${city1},${country1},${state1},${postal_code1}`);

if(city1==null){
    formContext.getAttribute('new_city').setValue(city);
}
if(country1==null){
    formContext.getAttribute('new_country').setValue(country);
}
if(state1==null){
    formContext.getAttribute('new_state').setValue(state);
}
if(postal_code1==null){
    formContext.getAttribute('new_zipcodepostalcode').setValue(postal_code);
}
alert(`${city},${country},${state},${postal_code}`);
}

function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
  currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
     

我尝试使用保存和新逻辑打开一个新的实体表单。 新实体表单打开,但字段值未在新方式中复制。

请帮我解决这个问题。 谢谢并提前!

【问题讨论】:

  • 你试过 cloneNode 了吗?

标签: javascript clone dynamics-365


【解决方案1】:

您需要使用您的 cloneid 记录调用 Xrm.Navigation.openForm。

// Load newly copy record
     var entityFormOptions = {};
     entityFormOptions["entityName"] = "stdseries";
     entityFormOptions["entityId"] = cloneId;
     // Open the form.
     Xrm.Navigation.openForm(entityFormOptions).then(
         function (success) {
             formContext.data.refresh();        
         },
         function (error) {
             
         });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多