Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // const packID = '156950344216170038' // ITSM
- const packID = '155931135900000002' // SIMPL
- const obj = {
- "172778902704801735": {
- "ru": "Инциденты в разрезе причин",
- "en": "Incidents by cause"
- },
- "172758840504375611": {
- "ru": "Портал",
- "en": "Portal"
- },
- "172758832900858846": {
- "ru": "Портал",
- "en": "Portal"
- },
- "172709497603771004": {
- "ru": "Все жалобы",
- "en": "All complaints"
- }
- }
- function iterateKeys(obj) {
- for (let key in obj) {
- const column_id = getColumnId(key)
- let rec = getRecord(key, '156628684306200767'); // ru
- if (rec && rec.sys_id) {
- rec.setValue('value', obj[key].ru);
- rec.update();
- } else {
- let newRec = new SimpleRecord('sys_translation'); // создаем новый объект
- newRec.setValue('record_id', key);
- newRec.setValue('language_id', '156628684306200767'); // ru
- newRec.setValue('column_id', column_id);
- newRec.setValue('value', obj[key].ru);
- newRec.insert();
- }
- rec = getRecord(key, '156628684306541141'); // en
- if (rec && rec.sys_id) {
- rec.setValue('value', obj[key].en);
- rec.update();
- } else {
- let newRec = new SimpleRecord('sys_translation'); // создаем новый объект
- newRec.setValue('record_id', key);
- newRec.setValue('language_id', '156628684306541141'); // en
- newRec.setValue('column_id', column_id);
- newRec.setValue('value', obj[key].en);
- newRec.insert();
- }
- }
- }
- // Пример использования функции:
- iterateKeys(obj);
- function getRecord(key, langID) {
- const record = new SimpleRecord('sys_translation');
- record.addQuery('record_id', key);
- record.addQuery('language_id', langID);
- record.addQuery('application_id', packID);
- record.orderByDesc('record_id');
- record.setLimit(1);
- record.query();
- if (record.next()) return record;
- return null; // возвращаем null, если запись не найдена
- }
- function getColumnId(key) {
- const record = new SimpleRecord('sys_translation');
- record.addQuery('record_id', key);
- record.orderByDesc('record_id');
- record.setLimit(1);
- record.query();
- if (record.next()) return record.getValue('column_id')
- return null; // возвращаем null, если запись не найдена
- }
Advertisement
Add Comment
Please, Sign In to add comment