How can i change the readonly department name in Document,? after save the document

Anuj20
Tera Contributor

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

Anuj20_1-1698320184960.png

 

6 REPLIES 6

Harsh_Deep
Giga Sage
Giga Sage

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.

Thanks Harsh, 

 

Background Script is Safe for Prod Instance ? as, background script always have a chance to loose data and system disruption.

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.

Anand Kumar P
Giga Patron
Giga Patron

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