- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 01:01 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 04:33 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 03:25 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 04:33 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 03:34 AM
var gr= new GlideRecord('wm_task');
gr.addQuery('sys_id', '047e9966db4993449af93c9b7c9619ac');
gr.query();
if(gr.next()){
{
gr.company = 'bd86c5d54d4b41007e97afc68bc60881';
gr.setWorkflow(false);
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:38 AM
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