How can i change the readonly department name in Document,? after save the document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:38 AM
Hi All
Please help to change the department name in the Document.
this Department field is a reference field for department table. and it always get read only once we save the new Document .
but now after save i need to change the Department as on of my team mate select a wrong department here. as in Screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:44 AM
Hello @Anuj20 ,
Use this in background script-
var gr = new GlideRecord('table_name_of_this_document');
gr.addQuery('number','DOC0010029');
gr.query();
if(gr.next()){
gr.backend_name_of_document_field='sys_id_of_new_document';
gr.setWorkflow(false);
gr.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:54 AM
Thanks Harsh,
Background Script is Safe for Prod Instance ? as, background script always have a chance to loose data and system disruption.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 04:58 AM - edited 10-26-2023 05:06 AM
Hello @Anuj20
Then use same code in fix script and execute it.
var gr = new GlideRecord('table_name_of_this_document');
gr.addQuery('number','DOC0010029');
gr.setLimit(1);
gr.query();
if(gr.next()){
gr.backend_name_of_document_field='sys_id_of_new_document';
gr.setWorkflow(false);
gr.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:03 AM
Hi @Anuj20 ,
You can run a fix script to update read-only field document with if condition and setlimt to 1 no issue in production i will update only specific record.
var tableName = 'table_name_of_this_document';
var targetNumber = 'DOC001289';
var newDocumentSysID = 'sys_id_of_new_document';
var gr = new GlideRecord(tableName);
gr.addQuery('number', targetNumber);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.targetField = newDocumentSysID;
gr.setWorkflow(false); // Disable workflow for this update
gr.update();
}
Please mark it as helpful and solution proposed if its serve you purpose.
Thanks,
Anand