Want to remove a prefix from a field

Poorva Bhawsar
Mega Sage

Hi Community,

 

I want to remove 'ROCG' keyword from a field which contains values as ROCGTPO12344 etc in this field. 

 

I have written a BR but its throwing some error.

var record = new GlideRecord('xyz');
record.query();
while (record.next()) {
 
        record.abc= record.abc.replace('ROCG', '');
        record.setWorkflow(false); //Do not run business rules
        record.autoSysFields(false); //Do not update system fields
        record.update();
    }
 
But its throwing error when i am replacing it.
 
Thanks
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Poorva Bhawsar 

use this

var record = new GlideRecord('xyz');
record.query();
while (record.next()) {

record.abc= record.abc.toString().replace('ROCG', '');
record.setWorkflow(false); //Do not run business rules
record.autoSysFields(false); //Do not update system fields
record.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Poorva Bhawsar 

use this

var record = new GlideRecord('xyz');
record.query();
while (record.next()) {

record.abc= record.abc.toString().replace('ROCG', '');
record.setWorkflow(false); //Do not run business rules
record.autoSysFields(false); //Do not update system fields
record.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Poorva Bhawsar 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Poorva Bhawsar 

 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Poorva Bhawsar 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader