|
| 1 | +There is a simple way, how the generated SQL query can be checked, without activating the SQL Debugger feature in the navigator. |
| 2 | + |
| 3 | +Here you can see a small code snippet: |
| 4 | +```JS |
| 5 | +try { |
| 6 | + gs.trace(true); |
| 7 | + var incGr = new GlideRecord("incident"); |
| 8 | + incGr.setLimit(10); |
| 9 | + incGr.orderByDesc("sys_created_on"); |
| 10 | + incGr.query(); |
| 11 | +} |
| 12 | +finally { |
| 13 | + gs.trace(false); |
| 14 | +} |
| 15 | +``` |
| 16 | +By enabling the trace feature, the generated SQL query will be visible in the output: |
| 17 | +```SQL |
| 18 | +SELECT task0.`sys_id` |
| 19 | +FROM task task0 |
| 20 | +IGNORE index(sys_created_on) |
| 21 | +WHERE task0.`sys_class_name` = 'incident' |
| 22 | +ORDER BY task0.`sys_created_on` DESC |
| 23 | +LIMIT 0, 10 |
| 24 | +``` |
| 25 | + |
| 26 | +Another example: |
| 27 | +```JS |
| 28 | +try { |
| 29 | + gs.trace(true); |
| 30 | + var incGr = new GlideRecord("incident"); |
| 31 | + incGr.setLimit(10); |
| 32 | + incGr.orderByDesc("sys_created_on"); |
| 33 | + incGr.query(); |
| 34 | + while (incGr.next()) { |
| 35 | + gs.info("Number: " + incGr.getValue("number") + " Created: " + incGr.getValue("sys_created_on")); |
| 36 | + } |
| 37 | +} |
| 38 | +finally { |
| 39 | + gs.trace(false); |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +```SQL |
| 44 | +SELECT task0.`sys_id` |
| 45 | +FROM task task0 |
| 46 | +IGNORE index(sys_created_on) |
| 47 | +WHERE task0.`sys_class_name` = 'incident' |
| 48 | +ORDER BY task0.`sys_created_on` DESC |
| 49 | +LIMIT 0, 10 |
| 50 | +``` |
| 51 | +```SQL |
| 52 | +SELECT task0.`parent`, |
| 53 | + task0.`a_ref_3` AS `caused_by`, |
| 54 | + task0.`watch_list`, |
| 55 | + task0.`upon_reject`, |
| 56 | + task0.`sys_updated_on`, |
| 57 | + task0.`a_str_5` AS `origin_table`, |
| 58 | + task0.`approval_history`, |
| 59 | + task0.`skills`, |
| 60 | + task0.`number`, |
| 61 | + task0.`state`, |
| 62 | + task0.`sys_created_by`, |
| 63 | + task0.`knowledge`, |
| 64 | + task0.`order`, |
| 65 | + task0.`cmdb_ci`, |
| 66 | + task0.`delivery_plan`, |
| 67 | + task0.`impact`, |
| 68 | + task0.`contract`, |
| 69 | + task0.`active`, |
| 70 | + task0.`work_notes_list`, |
| 71 | + task0.`priority`, |
| 72 | + task0.`sys_domain_path`, |
| 73 | + task0.`rejection_goto`, |
| 74 | + task0.`business_duration`, |
| 75 | + task0.`group_list`, |
| 76 | + task0.`approval_set`, |
| 77 | + task0.`wf_activity`, |
| 78 | + task0.`universal_request`, |
| 79 | + task0.`short_description`, |
| 80 | + task0.`correlation_display`, |
| 81 | + task0.`work_start`, |
| 82 | + task0.`delivery_task`, |
| 83 | + task0.`additional_assignee_list`, |
| 84 | + task0.`a_int_1` AS `notify`, |
| 85 | + task0.`sys_class_name`, |
| 86 | + task0.`service_offering`, |
| 87 | + task0.`closed_by`, |
| 88 | + task0.`follow_up`, |
| 89 | + task0.`a_ref_7` AS `parent_incident`, |
| 90 | + task0.`a_ref_5` AS `reopened_by`, |
| 91 | + task0.`reassignment_count`, |
| 92 | + task0.`assigned_to`, |
| 93 | + task0.`variables`, |
| 94 | + task0.`sla_due`, |
| 95 | + task0.`comments_and_work_notes`, |
| 96 | + task0.`agile_story`, |
| 97 | + task0.`escalation`, |
| 98 | + task0.`upon_approval`, |
| 99 | + task0.`correlation_id`, |
| 100 | + task0.`made_sla`, |
| 101 | + task0.`a_int_6` AS `child_incidents`, |
| 102 | + task0.`a_int_8` AS `hold_reason`, |
| 103 | + task0.`task_effective_number`, |
| 104 | + task0.`a_ref_6` AS `resolved_by`, |
| 105 | + task0.`sys_updated_by`, |
| 106 | + task0.`opened_by`, |
| 107 | + task0.`user_input`, |
| 108 | + task0.`sys_created_on`, |
| 109 | + task0.`sys_domain`, |
| 110 | + task0.`route_reason`, |
| 111 | + task0.`a_int_4` AS `calendar_stc`, |
| 112 | + task0.`closed_at`, |
| 113 | + task0.`business_service`, |
| 114 | + task0.`a_str_11` AS `business_impact`, |
| 115 | + task0.`a_ref_2` AS `rfc`, |
| 116 | + task0.`time_worked`, |
| 117 | + task0.`expected_start`, |
| 118 | + task0.`opened_at`, |
| 119 | + task0.`work_end`, |
| 120 | + task0.`a_dtm_1` AS `reopened_time`, |
| 121 | + task0.`a_dtm_2` AS `resolved_at`, |
| 122 | + task0.`a_ref_4` AS `caller_id`, |
| 123 | + task0.`a_str_3` AS `subcategory`, |
| 124 | + task0.`work_notes`, |
| 125 | + task0.`a_str_7` AS `close_code`, |
| 126 | + task0.`assignment_group`, |
| 127 | + task0.`a_int_5` AS `business_stc`, |
| 128 | + task0.`a_str_10` AS `cause`, |
| 129 | + task0.`description`, |
| 130 | + task0.`a_str_2` AS `origin_id`, |
| 131 | + task0.`calendar_duration`, |
| 132 | + task0.`close_notes`, |
| 133 | + task0.`sys_id`, |
| 134 | + task0.`contact_type`, |
| 135 | + task0.`a_int_2` AS `incident_state`, |
| 136 | + task0.`urgency`, |
| 137 | + task0.`a_ref_1` AS `problem_id`, |
| 138 | + task0.`company`, |
| 139 | + task0.`activity_due`, |
| 140 | + task0.`a_int_3` AS `severity`, |
| 141 | + task0.`comments`, |
| 142 | + task0.`approval`, |
| 143 | + task0.`due_date`, |
| 144 | + task0.`sys_mod_count`, |
| 145 | + task0.`a_int_7` AS `reopen_count`, |
| 146 | + task0.`location`, |
| 147 | + task0.`a_str_1` AS `category` |
| 148 | +FROM task task0 |
| 149 | +WHERE task0.`sys_class_name` = 'incident' |
| 150 | + AND task0.`sys_id` IN ('9060975f472d4210a53cdbe4116d4311', |
| 151 | + '9e7f9864532023004247ddeeff7b121f', |
| 152 | + 'd71f7935c0a8016700802b64c67c11c6', |
| 153 | + 'a9a16740c61122760004fe9095b7ddca', |
| 154 | + 'd71b3b41c0a8016700a8ef040791e72a', |
| 155 | + 'd7195138c0a8016700fd68449cfcd484', |
| 156 | + 'd7158da0c0a8016700eef46c8d1f3661', |
| 157 | + 'ef43c6d40a0a0b5700c77f9bf387afe3', |
| 158 | + 'ef4225a40a0a0b5700d0b8a790747812', |
| 159 | + 'a9e30c7dc61122760116894de7bcc7bd') |
| 160 | +``` |
0 commit comments