Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const condition_ = `(value!=Updated by^value!=Created by^value!=Created at^value!=Updated at^value!=Work Notes^value!=VCS Record^value!=Additional Comments^value!=ID^column_id.column_name!=dynamic_link_name^value!=Default^sys_created_at>=2024-09-05 12:08:08)^GROUPBYrecord_id&page=1`
- const ids = getIDsByCondition(condition_)
- let idsUnic = [...new Set(ids)];
- // ss.info( idsUnic );
- const newCondition = getConditionByTableAndIDs(idsUnic, 'sys_translation')
- ss.info(newCondition)
- function getConditionByTableAndIDs(listOfPrb, tableName) {
- // Преобразуем строку с ID в массив
- if(typeof listOfPrb == 'object') {
- listOfPrb = listOfPrb.join(',')
- }
- var prbIds = listOfPrb.split(',').map(id => id.trim())
- // Создаем объект GlideRecord для таблицы itsm_incident
- var grIncident = new SimpleRecord(tableName);
- // Добавляем запрос для поиска инцидентов по списку ID
- grIncident.addQuery('sys_id', 'IN', prbIds);
- return grIncident.getConditionQuery();
- }
- function getIDsByCondition(condition_) {
- let record = new SimpleRecord('sys_translation');
- record.addEncodedQuery(condition_);
- record.orderByDesc('record_id');
- // record.setLimit(30);
- record.query();
- ss.info('всего строк: ' + record.getRowCount())
- const arr = [];
- while (record.next()) {
- arr.push(record.sys_id)
- }
- ss.info('ОШИБКИ = ' + record.getErrors());
- return arr
- }
- function getTranslationsByCondition(condition_, language, tableName) {
- // Define language IDs based on input language
- const languageIDMap = {
- "ru": "156628684306200767", // Russian language ID
- "en": "156628684306541141" // English language ID
- };
- const targetLanguageID = languageIDMap[language]; // Get the appropriate language ID
- const translations = {}; // Object to store translations by record_id
- let record = new SimpleRecord('sys_translation');
- record.addEncodedQuery(condition_);
- record.addQuery('language_id', targetLanguageID);
- record.orderByDesc('record_id');
- record.query();
- // Loop through records to collect translations
- while (record.next()) {
- const recordID = record.record_id;
- const languageID = record.getValue('language_id')
- const hasProblem = getCountTranslate(recordID)
- const gr = new SimpleRecord(tableName)
- gr.get(recordID)
- let answer = !!gr.sys_id && !!gr.active && !!hasProblem
- // ss.info(answer)
- // ss.info('languageID')
- const translationValue = record.value;
- if (answer) {
- translations[recordID] = {
- "ru": "",
- "en": ""
- };
- }
- // Assign translation value to the correct language key
- if (answer) {
- translations[recordID][language] = translationValue;
- }
- }
- // ss.info('Translations object = ' + JSON.stringify(translations));
- return translations;
- }
- // Example use case
- const language = 'en'; // Set to either 'ru' or 'en'
- const translationObj = getTranslationsByCondition(newCondition, language, 'sys_ui_action');
- ss.info(JSON.stringify(translationObj));
- function getCountTranslate(recordID) {
- const gr = new SimpleRecord('sys_translation');
- gr.addQuery('record_id', recordID);
- gr.query();
- let hasCyrillic = false; // Flag for Cyrillic characters (Russian)
- let hasLatin = false; // Flag for Latin characters (English)
- while (gr.next()) {
- const value = gr.value;
- const languageID = gr.getValue('language_id');
- if (languageID === '156628684306200767') { // Russian language ID
- // Check if the value contains Cyrillic characters (regular expression for Cyrillic)
- hasCyrillic = /[а-яА-ЯЁё]/.test(value);
- }
- if (languageID === '156628684306541141') { // English language ID
- // Check if the value contains Latin characters (regular expression for Latin alphabet)
- hasLatin = /[a-zA-Z]/.test(value);
- }
- }
- const answer = !hasCyrillic || !hasLatin;
- // Return true if either condition is not met: no Cyrillic or no Latin characters
- return answer
- }
Advertisement
Add Comment
Please, Sign In to add comment