How do I create a self join database view for sys_choice?

curtisrowell
Mega Expert

I want to be able to create a database view for each of the 5 translation tables, sys_translated, sys_translated_text, sys_documentation, sys_choice, sys_ui_message which will show me which records of language 'x' do not also exist in other languages.

In our instances, we have EN (default), ES (Spanish), JA (Japanese), ZH (Simplified Chinese) enabled.   with 10's of thousands of records to be validated in just one language, it fast becomes necessary to have a way to automate this.   To this end, I'd like to look at creating a view which takes the "Value" field in sys_choice where language=en and search for the same Value/Table/Element combination in another language.   If none are found, flag that English record.   If none are found for 1 language but are found for 2 others, flag that record as missing that language.

1 ACCEPTED SOLUTION

I did see this but it didn't really make much sense to me.


View solution in original post

4 REPLIES 4

nishailame
ServiceNow Employee
ServiceNow Employee

https://community.servicenow.com/thread/159095




 


Thanks.


PS: Hit like, Helpful, Correct and Endorse, if it answers your question


I did see this but it didn't really make much sense to me.


Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

I would try a script approach (not really reporting, but well)



Below script is for the sys choice table, but can be a basis for the other tables.


It checks the choice tables, if translations are not available, it creates placeholder records, you can filter on, by searching for labels starting with #


Define the languaes in the array on the first line.



Hope this helps!




var langs = ['es','ja','zh']; //define languages in array



//query all english records


var gr = new GlideRecord('sys_choice');


gr.addEncodedQuery("language=en");


gr.orderBy('name');


gr.query();


while (gr.next()) {




      var myLangs = langs.slice(); //clone array


      var label = "#"+gr.getValue("label");


      var sys_id = gr.getValue("sys_id")



      //query for existing translations


      var q = new GlideRecord('sys_choice');


      q.addEncodedQuery("language!=en");


      q.addQuery("table",gr.getValue("table"));


      q.addQuery("element",gr.getValue("element"));


      q.addQuery("value",gr.getValue("value"));


      q.orderBy('name');


      q.query();


      while (q.next()) { //remove existing languages from array


          var idx = myLangs.indexOf(q.getValue('language'));


          if (idx >= 0)


              myLangs.splice(idx, 1);    


      }


   


      //insert new records for remaining tables


      for (var i = 0; i< myLangs.length;i++ ){


          var ins = new GlideRecord('sys_choice');


          ins.get(sys_id)


          ins.language = myLangs[i];


          ins.label = label; // add a # prefix, to easily filter todo translations


          ins.insert();


      }


}


I see where there were records where tagged with '#'; however, only those associated with one table, alm_asset, were tagged for a total of 52 records.   Japanese and Chinese have only just been activated so there should have been some 5k records at a minimum which were tagged thus for Japanese alone.




find_real_file.png