- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 11:47 PM
Hi Guys,
As per my requirement, Need to update all the group names which are having "HDPro" to "THDPro".
Tried with the following code: in Background script and Fix script.
var a =[];
var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("nameSTARTSWITHHDPro");
gr.query();
while (gr.next()) {
gs.print(gr.name);
var b = a.push(gr.group.name.toString());
var c = "T" + gr.name;
gs.print(c);
gr.update();
}
I am able to get all the records, But it is not updating the record(Group name)
Can you please suggest with your idea.
Leads are more appreciable.
Thanks in advance..
Santhosh.K
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 09:54 AM
Thankyou all for valueble thoughts.
My Work is done with following code.
************************
var gr1 = new GlideRecord("sys_user_group");
gr1.addEncodedQuery("nameSTARTSWITHHDPro");
gr1.query();
while (gr1.next()) {
gs.print(gr1.name);
gr1.name = "T" + gr1.name;
gs.print(gr1.name);
gr1.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 11:54 PM
Hi Santhosh,
I think this is an easy fix. I would try this
var a =[];
var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("nameSTARTSWITHHDPro");
gr.query();
while(gr.next()) {
gs.print(gr.name);
var b = a.push(gr.group.name.toString());
var name = gr.name.toString();
var newName = "T" + name;
gr.name = newName;
gs.print(newName);
gr.update();
}
if this was helpful please mark as so. If this solved your question please mark as correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 12:07 AM
Hi Santosh,
you are not updating the name field anywhere so it is not updating that column; update script as below
var c = "T" + gr.name;
gs.print(c);
gr.name = c;
gr.update();
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 12:09 AM
I think you are using too many lines of code, You can simplify this to
var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("nameSTARTSWITHHDPro");
gr.query();
while (gr.next()) {
gr.name = "T" + gr.name;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 09:54 AM
Thankyou all for valueble thoughts.
My Work is done with following code.
************************
var gr1 = new GlideRecord("sys_user_group");
gr1.addEncodedQuery("nameSTARTSWITHHDPro");
gr1.query();
while (gr1.next()) {
gs.print(gr1.name);
gr1.name = "T" + gr1.name;
gs.print(gr1.name);
gr1.update();
}