Background script to change read-only value

KazmiB90
Tera Expert

Hi, 

I am new to coding. Please show me what I need to do with my script to change a value for Company Field which is read-only in Task [task] Table? 

var gr = new GlideRecord('wm_task’);

gr.addQuery('sys_id', '047e9966db4993449af93c9b7c9619ac');

gr.query();

while(gr.next()){

gr.company = bd86c5d54d4b41007e97afc68bc60881;

gr.update();

}

 

Thank you, I would appreciate your help.

LH

1 ACCEPTED SOLUTION

Hi Brad, 

 

Thank you for your response. I figured my table was incorrect. I changed the table to Task and I was able to change the read-only value. 

 

var gr = new GlideRecord(‘task');

gr.addQuery('sys_id', '047e9966db4993449af93c9b7c9619ac');

gr.query();

while(gr.next()){

gr.company = ‘bd86c5d54d4b41007e97afc68bc60881’;

gr.update();

}

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

I am not familiar with the wm_task table, but I ran a test with a field on a table that is defined in the dictionary as read-only, and a fix script still updated the value, so start by changing this line

gr.company = 'bd86c5d54d4b41007e97afc68bc60881';

And it probably doesn't matter, but change 'while' to 'if' since this query will only return one record.  If this doesn't work, ensue that's a valid sys_id for a record on the core_company table - or whatever table the company field on wm_task is referencing, and that the sys_id in your addQuery line is correct for the record on wm_task that you want to update.  You can add lines in your script to write to the log like

gs.info('wm_task script running, record found');
gs.info('wm_task script running, company = ' + gr.company);

 

 

 

Hi Brad, 

 

Thank you for your response. I figured my table was incorrect. I changed the table to Task and I was able to change the read-only value. 

 

var gr = new GlideRecord(‘task');

gr.addQuery('sys_id', '047e9966db4993449af93c9b7c9619ac');

gr.query();

while(gr.next()){

gr.company = ‘bd86c5d54d4b41007e97afc68bc60881’;

gr.update();

}

chinmayap1
Kilo Expert
Hi ,
 
Whatever Brad said is correct,just make sure if you do not want any business rule to run on that table add setWorkflow(false) to your code.
var gr= new GlideRecord('wm_task');
gr.addQuery('sys_id', '047e9966db4993449af93c9b7c9619ac');
gr.query();
if(gr.next()){
{
gr.company = 'bd86c5d54d4b41007e97afc68bc60881';

gr.setWorkflow(false);

gr.update();

}
 
 
 

Sushant Kadam1
Kilo Guru

Hi,

You can change the field using GlideRecord() because GlideRecord defaults to running as a "system", it bypasses the security on the record and fields. Your script action (or almost any other server-side script) can update the field even if it is read-only.

 

Please mark as correct/helpful if it helps you.

Regards,

Sushant