Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Fix Script not pausing at Debug Break Points

stacylen196
Tera Contributor

Please reference the attachment.

I have Breakpoints set on every statement in the script.

I start debugger, opens separate window - then from original window, I run fix Script (not in background).  

Script completes without ever pausing for a breakpoint (and does not set my reports publish=false)

 

Help Please

StacyLen

 

// Fix script to set the 'Public' field of all reports to false

var gr = new GlideRecord('sys_report');
gr.query();

while (gr.next()) {
    // Get the value of the 'public' field
    var isPublic = gr.getValue('public');

    if (isPublic == 'true') {
        // Set the 'public' field to false
        gr.setValue('public', 'false');
        gr.update();
        gs.info("Report '" + gr.getValue('title') + "' (sys_id: " + gr.getUniqueValue() + ") set to private.");
    }
}
3 REPLIES 3

James Chun
Kilo Patron

Hi @stacylen196,

 

Looks like someone asked the exact same question in the past - Debugger is not stopping in the breakpoint in Fix ... - ServiceNow Community

 

Hope that helps, cheers

Sarthak Kashyap
Mega Sage

Hi @stacylen196 ,

 

The debugger will not work in a fix script. If you want to debug your code, you can run it in a background script and add gs.info() statements after the lines you want to debug. In fix script also you can use try/catch to check the error message.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Bert_c1
Kilo Patron

I found Google AI shows the same script:

 

var gr = new GlideRecord('sys_report');
gr.query();
while (gr.next()) {
  // Use getValue() to check the field's current value
  var isPublic = gr.getValue('public');
  if (isPublic == 'true') {
    // Use setValue() to change the field's value
    gr.setValue('public', 'false');
    gr.update();
    gs.info("Report '" + gr.getValue('title') + "' (sys_id: " + gr.getUniqueValue() + ") set to private.");
  }
}

However, there is no field named 'public' on the sys_report table.  So that script changes nothing in my instance. However, there is the 'is_published' field and a 'roles' field, where 'public' is shown. That combination seems to allow "public" access to the report.