
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 03:17 AM
Hi,
I have a new on change BR that will fire on change of a field.
Now I want all existing records (on sys_user_group) to run the BR once ... so the field X should be updated (by X again) ... .
When creating a job, that runs through all records and update the field with it's own value, no update will be done I assume ...
So how does the best practice would look like here to achieve the run of the BR?
Would be cool if you could provide some script I could modify.
THank you
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 07:23 AM
var roleID = "011ba5aa0a0a0b3001a439c580549134"; //role_delegator
var userGroup = new GlideRecord('sys_user_group');
userGroup.addNotNullQuery('manager');
userGroup.query();
while(userGroup.next()) {
// add role to new manager
var gr = new GlideRecord("sys_user_has_role");
gr.addQuery("user", userGroup.manager);
gr.addQuery("role", roleID);
gr.addQuery("granted_by", userGroup.sys_id);
gr.query();
if (gr.next())
gs.log(userGroup.manager.getDisplayValue() + " already has the role_delegator role for the " + userGroup.name + " group - not adding");
else {
gr.initialize();
gr.user = userGroup.manager;
gr.role = roleID;
gr.granted_by = userGroup.sys_id;
gr.inherited = false;
gr.insert();
gs.addInfoMessage(gs.getMessage("role_delegator role granted to") + " " +
userGroup.manager.getDisplayValue() + " " + gs.getMessage("in") + " " + userGroup.name + " " + gs.getMessage("group"));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 03:27 AM
Hi Vem,
If you want to populate the value of a new field created by you . Better way is to run the background script once to populate the data. If you can elaborate your requirement we can guide you in better way.
Regards,
Govind Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 03:32 AM
Hi,
the best way to update existing records is the Scheduled Job. You can use the same code of your business rule, the difference is that you have to inizialize a table record using the GlideRecord method.
Hope it helps!
Regards,
Valentina

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 03:40 AM
If fact I would just would like to just update all records without changing anything. But if I don't change anything the system will not do the update - correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 03:51 AM
Hi Vemffm,
In this case you can use one method to update the record forcefully.
setForceUpdate
public void setForceUpdate(boolean force) - Updates the record even if fields have not been changed.
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=c_GlideRecordAPI
Hope this helps you
Regards,
Govind Sharma