「kintone lookup」と組み合わせるとロックされたフィールドを除外します
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
} from "../types/ActionTypes";
|
||||
import { actionAddins } from ".";
|
||||
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
||||
import { Lookup } from "@kintone/rest-api-client/lib/src/KintoneFields/types/property";
|
||||
|
||||
interface Props {
|
||||
displayName: string;
|
||||
@@ -86,19 +87,24 @@ export class DataMappingAction implements IAction {
|
||||
): Promise<IActionResult> {
|
||||
this.actionProps = prop.actionProps;
|
||||
this.dataMappingProps = prop.ActionValue as Props;
|
||||
console.log(prop.ActionValue);
|
||||
console.log(context);
|
||||
let result = {
|
||||
canNext: true,
|
||||
result: "",
|
||||
} as IActionResult;
|
||||
try {
|
||||
const lookupFixedFieldCodes = await getLookupFixedFieldCodes(
|
||||
this.dataMappingProps.sources.app.id
|
||||
);
|
||||
|
||||
// createWithNull が有効な場合は、4 番目のパラメーターを true にして doUpdate 関数ブランチを実行します。
|
||||
if (this.dataMappingProps.dataMapping.createWithNull === true) {
|
||||
await doUpdate(
|
||||
this.dataMappingProps.dataMapping.data,
|
||||
this.dataMappingProps.sources.app.id,
|
||||
context,
|
||||
true // キーがない場合、またはキーでターゲットが見つからない場合に、マッピング条件によって新しいレコードを作成するかどうかを決定するために使用されます。
|
||||
true, // キーがない場合、またはキーでターゲットが見つからない場合に、マッピング条件によって新しいレコードを作成するかどうかを決定するために使用されます。
|
||||
lookupFixedFieldCodes
|
||||
);
|
||||
} else if (
|
||||
// キーがないと更新対象を取得できないため、この時点でのみ更新が行われます。 doUpdate 関数の 4 番目のパラメーターは false です。
|
||||
@@ -110,13 +116,15 @@ export class DataMappingAction implements IAction {
|
||||
this.dataMappingProps.dataMapping.data,
|
||||
this.dataMappingProps.sources.app.id,
|
||||
context,
|
||||
false
|
||||
false,
|
||||
lookupFixedFieldCodes
|
||||
);
|
||||
} else {
|
||||
await doCreate(
|
||||
this.dataMappingProps.dataMapping.data,
|
||||
this.dataMappingProps.sources.app.id,
|
||||
context
|
||||
context,
|
||||
lookupFixedFieldCodes
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -154,16 +162,21 @@ const doUpdate = async (
|
||||
mappingData: Mapping[],
|
||||
appId: string,
|
||||
context: any,
|
||||
needCreate: boolean
|
||||
needCreate: boolean,
|
||||
lookupFixedFieldCodes: string[]
|
||||
) => {
|
||||
const targetField = await findUpdateField(mappingData, appId, context);
|
||||
console.log(targetField);
|
||||
if (targetField.records.length === 0 && needCreate) {
|
||||
await doCreate(mappingData, appId, context);
|
||||
await doCreate(mappingData, appId, context, lookupFixedFieldCodes);
|
||||
} else {
|
||||
// マッピングデータを単純なオブジェクトに処理し、ソース値が変数の場合は変数を置き換えます。
|
||||
const mappingRules = mappingData
|
||||
.filter((m) => Object.keys(m.from).length > 0)
|
||||
.filter(
|
||||
(m) =>
|
||||
Object.keys(m.from).length > 0 &&
|
||||
!lookupFixedFieldCodes.includes(m.to.fields[0].code)
|
||||
)
|
||||
.map((m) => {
|
||||
if (m.from.objectType === "variable") {
|
||||
return {
|
||||
@@ -198,8 +211,6 @@ const doUpdate = async (
|
||||
}
|
||||
);
|
||||
|
||||
console.log(updateRecords);
|
||||
|
||||
await client.record.updateRecords({
|
||||
app: appId,
|
||||
records: updateRecords,
|
||||
@@ -242,7 +253,8 @@ const findUpdateField = async (
|
||||
const doCreate = async (
|
||||
mappingData: Mapping[],
|
||||
appId: string,
|
||||
context: any
|
||||
context: any,
|
||||
lookupFixedFieldCodes: string[]
|
||||
) => {
|
||||
const record = mappingData
|
||||
.filter(
|
||||
@@ -253,6 +265,7 @@ const doCreate = async (
|
||||
item.to.fields &&
|
||||
item.to.fields.length > 0
|
||||
)
|
||||
.filter((item) => !lookupFixedFieldCodes.includes(item.to.fields[0].code))
|
||||
.reduce((accumulator, item) => {
|
||||
return {
|
||||
...accumulator,
|
||||
@@ -268,3 +281,13 @@ const doCreate = async (
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const getLookupFixedFieldCodes = async (appId: string) => {
|
||||
return await client.app
|
||||
.getFormFields({ app: appId, lang: "ja" })
|
||||
.then((resp) =>
|
||||
Object.values(resp.properties)
|
||||
.filter((f) => (f as Lookup).lookup !== undefined)
|
||||
.flatMap((f) => (f as Lookup).lookup.fieldMappings.map((m) => m.field))
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user