プロセス管理をコピーするするtipsを参考にレコードの条件通知の設定を別アプリにコピーしてみました
(() => {
"use strict";
const COPY_APPID = 37; //コピー先のアプリの番号に変えてください
function getProcessManagement() {
const body = {
app: kintone.app.getId(),
};
return kintone
.api(
kintone.api.url("/k/v1/app/notifications/perRecord.json", true),
"GET",
body
)
.then(
(resp) => {
console.log(resp);
return resp;
},
(error) => {
return kintone.Promise.reject(error.message);
}
);
}
function putProcessManagement(original) {
const body = {
app: COPY_APPID,
notifications: original.notifications,
};
return kintone
.api(
kintone.api.url("/k/v1/preview/app/notifications/perRecord.json", true),
"PUT",
body
)
.then(
(resp) => {},
(error) => {
return kintone.Promise.reject(error.message);
}
);
}
function deployProcessManagement() {
const body = {
apps: [
{
app: COPY_APPID,
},
],
};
return kintone
.api(kintone.api.url("/k/v1/preview/app/deploy", true), "POST", body)
.then(
(resp) => {
alert(
"アプリ番号「" +
COPY_APPID +
"」にレコードの条件通知の設定をコピーしました。"
);
},
(error) => {
return kintone.Promise.reject(error.message);
}
);
}
kintone.events.on(["app.record.index.show"], (event) => {
if (document.getElementById("CopyRecordManagement") !== null) {
return;
}
const menuButton = document.createElement("button");
menuButton.id = "CopyRecordManagement";
menuButton.innerHTML = "Copy レコードの条件通知";
menuButton.onclick = function () {
if (
window.confirm(
"アプリ番号「" +
COPY_APPID +
"」にレコードの条件通知の設定をコピーしますか?"
)
) {
getProcessManagement()
.then(putProcessManagement)
.then(deployProcessManagement)
.catch((error) => {
alert(error);
});
}
};
kintone.app.getHeaderMenuSpaceElement().appendChild(menuButton);
});
})();