We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to update Read only Custom field to Null for 100 of records in alm_hardware Table in Fix script?

VIKAS45
Tera Guru

How to update Read only Custom field to Null for 100 of records in alm_hardware Table using Fix script or any other Method?

4 REPLIES 4

Deepak Shaerma
Mega Sage

Hi @VIKAS45 

Step 1: Navigate to Background Script  Scripts - Background 
Script:

    var tableName = 'alm_hardware'; 
    var customFieldName = 'u_custom_field'; // REPLACE with your field name
    var gr = new GlideRecord(tableName);
    gr.query(); // Execute the query to retrieve the records
    
    var count = 0;
    while (gr.next()) {
      gr.setValue(customFieldName, ''); // Set the field value to null (empty string in this context)
      gr.setWorkflow(false); // Optionally, skip business rules, if necessary
      gr.update(); // Update the record
      count++;
    }
    
    gs.info(count + ' records updated in ' + tableName);



Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

 

Basheer
Mega Sage

Hi @VIKAS45 

You can use either fix scripts or background scripts or you can even schedule it 

below is the sample code

var almAsset= new GlideRecord("alm_hardware");
almAsset.query();
while (almAsset.next())
 {
almAsset.customFieldName= " "; 
almAsset.update(); 
 }
Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Deborah Brown L
Kilo Sage

Hi @VIKAS45 ,

 

Can use a background script or fix script.

please find the script below,

    var gr = new GlideRecord('alm_hardware');
    //gr.addQuery('state','in use'); // write the query
    gr.query(); 
    gr.autoSysFields(false); //// so that the records don't have system updates
    gr.setLimit(100); // so it won't run for other records
    while (gr.next()) {
      gr.fieldname = ''; // Set the field value to null
      gr.setWorkflow(false); // Necessary if you are updating a bulk records 
      gr.update(); // Update the record
    }
 

abhishekdalvi
Tera Guru

Hi @VIKAS45 ,

 

You can use background script or fix script.

var gr_hardware = new GlideRecord("alm_hardware");
gr_hardware.addEncodedQuery(""); // Add your encoded query here which filters your required records
gr_hardware.query();

while (gr_hardware.next())
{
    gr_hardware.autoSysFields(false); // this will prevent updating updated by and updated field, use if required.
    gr_hardware.setWorkflow(false); // skip business rules
    gr_hardware.setValue(customFieldName, ''); // Set the field value to null
    gr_hardware.update(); 
}

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me.

 

Thank you!

Regards,
Abhishek Dalvi