- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 10:44 AM
I'm trying to set up a business rule to check if the data in a field called control_number in another table matches the current record number. If yes, then in the current record, I want to change the internal_validation_performed field to true.
I've tried it as a before and after rule. I've selected update and insert. I can't seem to get it to work. I've added an info message throughout and no matter what, the info message is returned successfully (regardless if the query requirements are met), meaning the query is not working properly. Can anyone help?
(function executeRule(current, previous /*null when async*/) {
var currentNumber = current.getValue('number');
var controlTests = new GlideRecord('x_hotm_orm_risk_registry');
controlTests.addQuery('control_number', currentNumber);
controlTests.query();
if (controlTests.next()) {
current.setValue('internal_validation_performed', true);
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 02:00 PM
One other thing to consider...
What type of field is Number and what type of field is Control Number? Are they both reference, is one a string and one a reference, etc?
This may be the reason the query isn't working...maybe you are getting a sys_id from a reference, but one of the fields is a string field which is text.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 02:08 PM
That was it! The control_number reference field references sys IDs. As soon as I changed number to sys_ID, it started working properly. Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 10:52 AM
Hi @JWayner ,
Hope you are doing great .
Use After Business rule , and try to use current.setWorkflow (false) to avoid retriggering the BR.
(function executeRule(current, previous /*null when async*/) { var currentNumber = current.getValue('number'); var controlTests = new GlideRecord('x_hotm_orm_risk_registry'); controlTests.addQuery('control_number', currentNumber); controlTests.query(); if (controlTests.next()) { current.setValue('internal_validation_performed', true); current.setWorkflow(false); // To prevent retriggering the business rule current.update(); // Save the changes to the current record } })(current, previous);
Please try using this updated script,
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 11:17 AM
Thanks for your quick response, Riya. Unfortunately, it's still not working. The only way I seem to be able to get anything to happen is by adding the source table as a variable and referencing it in the currentNumber variable. If I do this, the internal_validation_performed field becomes true in every record.
(function executeRule(current, previous /*null when async*/) {
var controlTable = new GlideRecord ('x_hotm_orm_control_registry');
var currentNumber = controlTable.getValue('number');
var controlTests = new GlideRecord('x_hotm_orm_risk_registry');
controlTests.addQuery('control_number', currentNumber);
controlTests.query();
if (controlTests.next()) {
current.setValue('internal_validation_performed', true);
current.setWorkflow(false); // To prevent retriggering the business rule
current.update(); // Save the changes to the current record
}
})(current, previous);