com.glide.script.RhinoEcmaError: "readOnly" is not defined - ERROR

Suresh11
Tera Contributor

When running the below script I am getting an error on the logs:

 

com.glide.script.RhinoEcmaError: "readOnly" is not defined.
<refname> : Line(1) column(0)
==> 1: readOnly

 

The code is looping through but the records are not deleted. Appreciate any help with this.

 

var redactJournal = new GlideRecord('sys_journal_field');
redactJournal.query('element_id', caseGr.sys_id);
redactJournal.query();
while (redactJournal.next()) {
gs.info('Journal 111 updated/deleted');
// redactJournal.setValue('value', 'Data Redacted');
// redactJournal.update();
redactJournal.deleteRecord();
}

7 REPLIES 7

Vishal Birajdar
Giga Sage

Hi Suresh11

 

Second line should be :

var redactJournal = new GlideRecord('sys_journal_field');
redactJournal.addQuery('element_id', caseGr.sys_id);
redactJournal.query();
while (redactJournal.next()) {
gs.info('Journal 111 updated/deleted');
// redactJournal.setValue('value', 'Data Redacted');
// redactJournal.update();
redactJournal.deleteRecord();

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi Vishal,

Thanks for the response. I have updated that but still the journal entries are not deleted. Still getting the warning and the journal entries are not deleted:

 

com.glide.script.RhinoEcmaError: "readOnly" is not defined.
<refname> : Line(1) column(0)
==> 1: readOnly

 

 

Full script:

 

// List of sensitive fields on HR Cases that need redaction
var sensitiveFields = ['short_description', 'rich_description'];
var sensitiveFieldsTask = ['short_description', 'rich_description']; // List of sensitive fields on HR Case Tasks

// Define the number of days before the cutoff date
var daysBefore = 15;

// Calculate the cutoff date
var cutOffDate = new GlideDateTime();
cutOffDate.addDaysLocalTime(-daysBefore);
var cutOffDateStr = cutOffDate.getDate(); // Convert the cutoff date to a string

// Log the cutoff date
gs.info('Cutoff Date: ' + cutOffDateStr);

// Create a GlideRecord for the HR case table and Query
var caseGr = new GlideRecord('sn_hr_core_case_workforce_admin');
caseGr.addQuery('sys_created_on', 'STARTSWITH', cutOffDateStr);
caseGr.query();

// Iterate through the selected HR cases and redact
while (caseGr.next()) {
for (var fieldIndex = 0; fieldIndex < sensitiveFields.length; fieldIndex++) {
var field = sensitiveFields[fieldIndex];
caseGr[field] = 'Data Redacted';
}

// Update the case record
caseGr.update();

// Log the update action for the case
gs.info('Case ' + caseGr.number + caseGr.sys_id + ' updated');

var redactJournal = new GlideRecord('sys_journal_field');
redactJournal.addQuery('element_id', caseGr.sys_id);
redactJournal.query();
while (redactJournal.next()) {
gs.info('Journal 111 updated/deleted');
// redactJournal.setValue('value', 'Data Redacted');
// redactJournal.update();
redactJournal.deleteRecord();
}

 

// Create a GlideRecord for HR case tasks and Query all the Child of current HR case
var taskGr = new GlideRecord('sn_hr_core_task');
taskGr.addQuery('parent', caseGr.sys_id);
taskGr.query();

// Iterate through the selected tasks and redact
while (taskGr.next()) {
for (var taskFieldIndex = 0; taskFieldIndex < sensitiveFieldsTask.length; taskFieldIndex++) {
var taskField = sensitiveFieldsTask[taskFieldIndex];
taskGr[taskField] = 'Data Redacted';
}

// Update the task record
taskGr.update();

// Log the update action for the task
gs.info('Task ' + taskGr.number + ' updated');
}
}

 

Hello Suresh,

 

Can you please let me know where you are running this script?

is it fix script..??

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Scheduled job on HR scope