Skip to main content

ServiceNow - Table checks: check if table populated and last updated and updated by

 

function discoverTableInfo(tableName) { var bLog = true; //bLog=false; var grCMDB = new GlideRecord(tableName); grCMDB.orderByDesc('sys_updated_on'); grCMDB.query(); var iTotal = grCMDB.getRowCount(); if (iTotal > 0) { if (grCMDB.next()) { if (bLog) { gs.log('TABLE:' + tableName + ';' + 'TOTAL RECORDS:' + iTotal + ';' + ' last updated date:' + grCMDB.sys_updated_on + ' ;updated by=' + grCMDB.sys_updated_by, 'fixScript:itsm-16016'); } else { gs.print('TABLE:' + tableName + ';' + 'TOTAL RECORDS:' + iTotal + ';' + ' last updated date:' + grCMDB.sys_updated_on + ' ;updated by=' + grCMDB.sys_updated_by); } } } else { if (bLog) { gs.print('TABLE:' + tableName + ' IS EMPTY'); } else { gs.log('TABLE:' + tableName + ' IS EMPTY', 'fixScript:itsm-16016'); } } } var bTest = false; //bTest = true; if (bTest) { discoverTableInfo('cmdb_ci_azure_vm'); } else { discoverTableInfo('azure_action'); discoverTableInfo('azure_action_parameter'); discoverTableInfo('azure_alert_configuration'); discoverTableInfo('azure_alert_event'); discoverTableInfo('azure_alert_rule'); discoverTableInfo('azure_back_pool_back_ip_m2m'); discoverTableInfo('azure_back_pool_lb_out_rule_m2m'); discoverTableInfo('azure_back_pool_lb_rule_m2m'); discoverTableInfo('azure_billing_daily'); discoverTableInfo('azure_billing_monthly'); discoverTableInfo('azure_billing_text_block'); discoverTableInfo('azure_blob_snapshot'); discoverTableInfo('azure_datasource_type_mapping'); discoverTableInfo('azure_deployment'); discoverTableInfo('azure_deployment_operation'); discoverTableInfo('azure_deployment_output'); discoverTableInfo('azure_deployment_parameter'); discoverTableInfo('azure_ea_credential'); discoverTableInfo('azure_front_ip_lb_in_rule_m2m'); discoverTableInfo('azure_front_ip_lb_out_rule_m2m'); discoverTableInfo('azure_front_ip_lb_rule_m2m'); discoverTableInfo('azure_image_publisher'); discoverTableInfo('azure_job_config'); discoverTableInfo('azure_lb_inbound_nat_rule'); discoverTableInfo('azure_lb_outbound_nat_rule'); discoverTableInfo('azure_lb_probe'); discoverTableInfo('azure_lb_rule_probe_m2m'); discoverTableInfo('azure_load_balancing_rule'); discoverTableInfo('azure_offering_image_mapping'); discoverTableInfo('azure_opt_rule_vm'); discoverTableInfo('azure_region'); discoverTableInfo('azure_region_image_sub_mapping'); discoverTableInfo('azure_region_subscription_mapping'); discoverTableInfo('azure_report_download_log'); discoverTableInfo('azure_resource_type'); discoverTableInfo('azure_sas_credentials'); discoverTableInfo('azure_scheduled_script'); discoverTableInfo('azure_service_principal'); discoverTableInfo('azure_storage_accnts'); discoverTableInfo('azure_storage_account_key'); discoverTableInfo('azure_subscription'); discoverTableInfo('azure_template'); discoverTableInfo('azure_template_parameter'); discoverTableInfo('azure_template_to_variableset'); discoverTableInfo('azure_temp_param_ref_table_excl'); discoverTableInfo('azure_token_cache'); discoverTableInfo('azure_vm_size'); discoverTableInfo('azure_web_service'); discoverTableInfo('cmdb_ci_azure_approved_image'); discoverTableInfo('cmdb_ci_azure_availability_set'); discoverTableInfo('cmdb_ci_azure_blob'); discoverTableInfo('cmdb_ci_azure_container'); discoverTableInfo('cmdb_ci_azure_datacenter'); discoverTableInfo('cmdb_ci_azure_front_ip_config'); discoverTableInfo('cmdb_ci_azure_image'); discoverTableInfo('cmdb_ci_azure_ip_config'); discoverTableInfo('cmdb_ci_azure_lb_back_addr_pool'); discoverTableInfo('cmdb_ci_azure_load_balancer'); discoverTableInfo('cmdb_ci_azure_nic'); discoverTableInfo('cmdb_ci_azure_public_ip'); discoverTableInfo('cmdb_ci_azure_resource'); discoverTableInfo('cmdb_ci_azure_resource_group'); discoverTableInfo('cmdb_ci_azure_subnet'); discoverTableInfo('cmdb_ci_azure_subscription'); discoverTableInfo('cmdb_ci_azure_vhd'); discoverTableInfo('cmdb_ci_azure_vm'); discoverTableInfo('cmdb_ci_azure_vnet'); discoverTableInfo('discovery_azure_probe'); discoverTableInfo('ea_azure_credentials'); discoverTableInfo('imp_azure_billing'); discoverTableInfo('sc_azure_os_selection'); discoverTableInfo('sc_azure_template_cat_item'); discoverTableInfo('sc_azure_vm_cat_item'); discoverTableInfo('sn_azure_arm_template_link'); discoverTableInfo('sn_azure_vm_template_cat_item'); }

Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){

Get URL Parameter - server side script (portal or classic UI)

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }