Business rule to get Column name from Column label
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 06:33 PM
What is the best practice in business rules for this case?
If we have two tables as shown below and the status of table A is closed, we want to update the items in table B that match the choices in table A with today's date.
e.g.) Table A record with choice "apple" is closed -> update table B's apple item with today's date
Thank you very much in advance for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 07:25 PM
You can write Before/After update business rule on Table A
Conditions:
- Check if the status of Table A is closed
Action:
- Query Table B for items matching the choices in the closed record of Table A.
- For each matching item:
- Update the item with today's date.
Below is the sample Business rule, update the actual field names in business rule:
// Business rule script for updating Table B items when a record in Table A is closed
// Check if the record is being closed
if (current.state == 'closed') {
// Query Table B for items matching choices in the closed record of Table A
var tableBGr = new GlideRecord('Table_B');
tableBGr.addQuery('choice_field', current.choice_field); // Adjust 'choice_field' to your field name
tableBGr.query();
// Update matching items in Table B with today's date
while (tableBGr.next()) {
tableBGr.date_field = gs.now(); // Adjust 'date_field' to your date field name
tableBGr.update();
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks