|
| 1 | +/* As part of Yokohama release the problem of logging and calculating time taken by a piece of script has been addressesed by bringing standardized timing tools to the platform, enabling precise performance analysis with minimal effort and developers can isolate slow operations. |
| 2 | +
|
| 3 | +Use Case: Query overall incident record and bulk update with specific values. Need time taken for query and update. |
| 4 | +*/ |
| 5 | + |
| 6 | +/* |
| 7 | +console.time(label) |
| 8 | + Starts a timer with a unique label. Use this at the beginning of a code block you want to measure. |
| 9 | + |
| 10 | +console.timeLog(label, [data]) |
| 11 | + Logs the current duration of the timer without stopping it. Optional data can be appended for context. |
| 12 | + |
| 13 | +console.timeEnd(label) |
| 14 | + Stops the timer and logs the total execution time. |
| 15 | +*/ |
| 16 | + |
| 17 | +console.time("ProcessIncident"); |
| 18 | + |
| 19 | +var incidents = fetchData(); |
| 20 | +console.timeLog("ProcessIncident", "Data fetched"); |
| 21 | + |
| 22 | +transformData(incidents); |
| 23 | +console.timeLog("ProcessIncident", "Data transformed"); |
| 24 | + |
| 25 | +console.timeEnd("ProcessIncident"); |
| 26 | + |
| 27 | +function fetchData() { |
| 28 | + var gr = new GlideRecord("incident"); |
| 29 | + gr.addQuery("active", "true"); |
| 30 | + gr.query(); |
| 31 | + |
| 32 | + var results = []; |
| 33 | + while (gr.next()) { |
| 34 | + results.push(gr.getUniqueValue()); |
| 35 | + } |
| 36 | + return results; |
| 37 | +} |
| 38 | + |
| 39 | +function transformData(incidentIds) { |
| 40 | + var count = 0; |
| 41 | + for (var i = 0; i < incidentIds.length && count < 10; i++) { |
| 42 | + var gr = new GlideRecord("incident"); |
| 43 | + if (gr.get(incidentIds[i])) { |
| 44 | + gr.setValue("state", "7"); |
| 45 | + gr.setValue("close_code", "known error"); |
| 46 | + gr.setValue("close_notes", "Incident closed as part of bulk close"); |
| 47 | + gr.setValue("work_notes", "Incident closed as part of bulk close"); |
| 48 | + gr.update(); |
| 49 | + count++; |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments