GlideTableHierarchy - returns Not Defined Error

syddent
Kilo Contributor

I have some code embedded in a Duration script for a table.  

  var tableName = current.getTableName();

  1. gs.info('Table name is '+ tableName);

var table = new GlideTableHierarchy(tableName);

  if (tableName) {

            var baseTableName = table.getBase(tableName);

  gs.info('Parent table is '+baseTableName);

When the script is called (through an SLA Definition), the following error turns up in the logs

org.mozilla.javascript.EcmaError: "GlideTableHierarchy" is not defined.

  Caused by error in <refname> at line 18

  15: // Work out if "current" is a Task record or Task SLA and then get the "due_date" element from the Task

  16: var tableName = current.getTableName();

  17: gs.info('Table name is '+ tableName);

==> 18: var table = new GlideTableHierarchy('tableName');

  19: if (tableName) {

  20: var baseTableName = table.getBase(tableName);

  21: gs.info('Parent table is '+baseTableName);

I have tried this script as a part of the Audit scope and the Global scope and the error is the same.

Why is GlideTableHierarchy not recognized?

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Sydney,



It works only in Scoped Applications, not in Global.


Here is the test I did and worked for me:



- as example in scope Scoped App Client :



var table = new GlideTableHierarchy("task");


gs.info(table.getAllExtensions());



I get:



[0:00:00.002] Script completed in scope sn_appclient: script



sn_appclient: task,stale_ci_remediation,release_task,incident,orphan_ci_remediation,change_task,statemgmt_renew_lease_task,incident_task,kb_submission,dmn_demand,sc_req_item,service_task,idea,ticket,sc_task,sm_order,facilities_request,hr_case,hrextension,taskextension,reclassification_task,required_field_remediation,gsw_task,change_request,change_request_imac,em_remediation_task,itfm_sb_stmt,project_change_request,sysapproval_group,planned_task,dmn_requirement,pm_program,grc_remediation,pm_program_task,rm_feature,rm_enhancement,rm_epic,rm_defect,rm_story,rm_doc,rm_test,dmn_decision,rm_release,rm_release_scrum,rm_release_sdlc,rm_sprint,rm_release_phase,tm_test_plan,pm_project_task,pm_project_task_link,pm_project,rm_product,rm_task,rm_scrum_task,sn_grc_issue,tm_test_case_instance,sm_task,facilities_request_task,hr_task,release_phase,vtb_task,std_change_proposal,change_phase,problem_task,recommended_field_remediation,em_ci_severity_task,sc_request,kb_knowledge_base_request,reconcile_duplicate_task,sn_grc_indicator_task,issue,itfm_dispute,sn_hr_core_task,cert_follow_on_task,sn_hr_core_case,sn_hr_core_case_payroll,sn_hr_core_case_total_rewards,sn_hr_core_case_operations,sn_hr_core_case_talent_management,sn_hr_core_case_workforce_admin,sn_hr_core_case_relations,problem,chat_queue_entry (sys.scripts extended logging)


- I go back to Global and I get:



[0:00:00.001] Script completed in scope global: script



Evaluator: org.mozilla.javascript.EcmaError: "GlideTableHierarchy" is not defined. Caused by error in script at line 1   ==>     1: var table = new GlideTableHierarchy("task"); 2: gs.print(table.getAllExtensions()); 


View solution in original post

5 REPLIES 5

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Sydney,



It works only in Scoped Applications, not in Global.


Here is the test I did and worked for me:



- as example in scope Scoped App Client :



var table = new GlideTableHierarchy("task");


gs.info(table.getAllExtensions());



I get:



[0:00:00.002] Script completed in scope sn_appclient: script



sn_appclient: task,stale_ci_remediation,release_task,incident,orphan_ci_remediation,change_task,statemgmt_renew_lease_task,incident_task,kb_submission,dmn_demand,sc_req_item,service_task,idea,ticket,sc_task,sm_order,facilities_request,hr_case,hrextension,taskextension,reclassification_task,required_field_remediation,gsw_task,change_request,change_request_imac,em_remediation_task,itfm_sb_stmt,project_change_request,sysapproval_group,planned_task,dmn_requirement,pm_program,grc_remediation,pm_program_task,rm_feature,rm_enhancement,rm_epic,rm_defect,rm_story,rm_doc,rm_test,dmn_decision,rm_release,rm_release_scrum,rm_release_sdlc,rm_sprint,rm_release_phase,tm_test_plan,pm_project_task,pm_project_task_link,pm_project,rm_product,rm_task,rm_scrum_task,sn_grc_issue,tm_test_case_instance,sm_task,facilities_request_task,hr_task,release_phase,vtb_task,std_change_proposal,change_phase,problem_task,recommended_field_remediation,em_ci_severity_task,sc_request,kb_knowledge_base_request,reconcile_duplicate_task,sn_grc_indicator_task,issue,itfm_dispute,sn_hr_core_task,cert_follow_on_task,sn_hr_core_case,sn_hr_core_case_payroll,sn_hr_core_case_total_rewards,sn_hr_core_case_operations,sn_hr_core_case_talent_management,sn_hr_core_case_workforce_admin,sn_hr_core_case_relations,problem,chat_queue_entry (sys.scripts extended logging)


- I go back to Global and I get:



[0:00:00.001] Script completed in scope global: script



Evaluator: org.mozilla.javascript.EcmaError: "GlideTableHierarchy" is not defined. Caused by error in script at line 1   ==>     1: var table = new GlideTableHierarchy("task"); 2: gs.print(table.getAllExtensions()); 


Do we know if there is intent to make it available in Global?

I don't really know at this stage. I will ask back internally and come back once I have some feedback.

Community Alums
Not applicable

This will be helpful, the TableUtils API is roughly the Global equivalent
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_TableUtilsAPI