Business Rule not updating the required fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 06:01 AM
I'm trying to write a business rule that is running from the Position (sn_hr_core_position) table and I'm wanting it to run on the following triggers:
If 'Job Profile' -> 'Job Family' CHANGES
OR
If 'Job Profile' -> 'Job Family Group' CHANGES
The script for my business rule is:
If somebody could let me know what I'm doing wrong of if it's even possible to dot walk through fields, that would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 06:16 AM
Hi @matthew_hughes ,
Please check if the following code line, setting the sys_id as input.
userGR.get('sys_id', current.u_hr_profile.user);
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 06:19 AM - edited 11-05-2024 06:20 AM
That bit of code is fine. The business rule worked previously when the condition was:
Job Profile Changes
I'm trying to get the Business Rule to trigger if a field within another table changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 01:09 AM - edited 11-06-2024 01:17 AM
Well there's your problem. Your BR is run on the record you're updating. So if you're updating another record on another table, the BR will not trigger as there's no way for it to know that a value changed since it only triggers during current records insert, update, delete or query. You need to apply the BR on the other table and make it query the original table for your record.
For example:
We want to update an incident when the related problem's assignment group changes:
1. We create a BR in problem table.
2. Set condition to "assignment group changes"
3. Write a script that queries for an incident that has the problem associated with it:
var relatedInc = new GlideRecord('incident');
relatedInc.get('problem', current.sys_id.toString());
if(relatedInc.isValidRecord()){
relatedInc.work_notes = "Assignment group on related problem updated";
relatedInc.update();
}
With similar logic your job profile record/table should have a BR checking for the change and then triggering an update on the related position record.
EDIT: I'll clarify the BR a bit.
A BR is usually run when the record is inserted or updated. You can define whether the BR is run before or after the update. The BR has access to current record. If you update a record all BR's on that table will be triggered against that record as long as conditions match.
So your BR will check the conditions like
user is test user -> Current user is test user.
User changes -> User value was changed during this update. So before you pressed save/update you modified the user.
User.name changes -> This does nothing since when the BR checks if the name changed it doesn't see a change since the other table doesn't trigger an update on your current record when it's saving values.
Imagine that you're at home and someone asked you to check if the milk is bad.
You know whether it's bad or not, but you don't know when it went bad if it did. The milk doesn't alert you separately that it has gone bad.
Now imagine that you have milk on the table next to you and it's going bad. At some point you'll start smelling a weird smell and know that it's gone bad. That's kinda like a BR on another table sending you an update that the milk has now gone bad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 06:23 AM
your BR is dot walking and then checks the Changes operator. This won't work.
Why not have the BR on the Table being referred by Job Profile field with condition as "Job Family" changes or "Job Family Group" changes?
Then search in sn_hr_core_position table the correct record and update it.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader