実現したい:Javasriptカスタマイズにアップロードした内容を反映させたい
custom.jsを反映させたい
エラーなどは起きないが反映されない
ネットワークを確認するとName:download.do?app=9&jsType=DESKTOP&contentId=94&hash=f9041ff2cd0d39c3ffda4ed7c0371f0a562826e8の
「content-disposition:attachment; filename="custom.js”」
何回か削除や再アップロード、名前を変えてアップロード
アップロード時にOSまたはブラウザがファイルのMIMEタイプを text/plain として送信していると可能性のためにレジストリエディターでtext/javascriptに変更しても反映されなかった
実行したコードをコピー&ペーストしましょう
intone.events.on('app.record.detail.process.succeed', async (event) => {
const record = event.record;
console.log('=== デバッグ開始 ===');
console.log('ステータス値:', JSON.stringify(record.ステータス?.value));
console.log('経理ID値:', JSON.stringify(record.経理ID?.value));
if (!record.ステータス || record.ステータス.value !== '部署承認済み') {
console.log('スキップ理由: ステータス不一致');
return event;
}
try {
const DEST_APP_ID = 10;
const API_TOKEN = '';
const searchResponse = await fetch(
`/k/v1/records.json?app=${DEST_APP_ID}&query=${encodeURIComponent(`経理ID = "${record.経理ID.value}"`)}`,
{ headers: { 'X-Cybozu-API-Token': API_TOKEN } }
);
if (!searchResponse.ok) {
const errBody = await searchResponse.json();
throw new Error('検索APIエラー: ' + JSON.stringify(errBody));
}
const searchResult = await searchResponse.json();
console.log('検索結果件数:', searchResult.records?.length);
console.log('検索結果:', JSON.stringify(searchResult));
if (searchResult.records && searchResult.records.length > 0) {
const existingRecordId = searchResult.records[0].$id.value;
const putResponse = await fetch('/k/v1/record.json', {
method: 'PUT',
headers: {
'X-Cybozu-API-Token': API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({
app: DEST_APP_ID,
id: existingRecordId,
record: {
申請: { value: record.申請.value },
経理ID: { value: record.経理ID.value }
},
revision: -1
})
});
const putResult = await putResponse.json();
if (!putResponse.ok) {
throw new Error(putResult.message || '上書きエラー');
}
console.log('既存レコードの上書き成功:', putResult);
} else {
const postResponse = await fetch('/k/v1/record.json', {
method: 'POST',
headers: {
'X-Cybozu-API-Token': API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({
app: DEST_APP_ID,
record: {
申請: { value: record.申請.value },
経理ID: { value: record.経理ID.value }
}
})
});
const postResult = await postResponse.json();
if (!postResponse.ok) {
throw new Error(postResult.message || 'コピー先への書き込みエラー');
}
console.log('コピー先への書き込み成功:', postResult);
}
} catch (e) {
console.error('エラー:', e.message);
alert('データ同期エラー: ' + e.message);
}
return event;
});