Business rule to get Column name from Column label

honamiUeo
Tera Contributor

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.

honamiUeo_0-1709519523401.png

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.

1 REPLY 1

Maddysunil
Kilo Sage

@honamiUeo 

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