Field value change automatically

SAM321
Tera Contributor

Hi all, so i have a requiremnt to change the field value automatically and auto save.

(ie).. There is two custom tables Table A and Table B , 

Table A have field 'phase'(choice type) and Table B have field 'state'.(choice type)

when Table B field state is changed to 'work in progress' and saved, Table A field phase should change automatically to stock request (choice) and form  get auto saved. how to achieve this.

1 ACCEPTED SOLUTION

@SAM321 
1] Now your BR will be on Table B. (After Update) and Condition as State Changes to Work in Progress.

2] In script part: 

 

(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
 
var procNumber = current.procurement_number; //Here,give your 'procurement number' field bakend name.
   
 var gr = new GlideRecord("Table_A"); // Give your Table A name
 gr.addQuery('sys_id', procNumber);
 gr.query();
 if (gr.next()) {  
  gr.phase = "stock_request";  // Give your Phave filed backend name and its choice 'Stock request' value
  gr.update();
    }

})(current, previous);

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

Thank you

 

View solution in original post

11 REPLIES 11

Sonu Parab
Mega Sage
Mega Sage

Hi @SAM321 ,
1] To achieve above requirement you have to create one After Update Business Rule on the table B.

and in When to Run section add condition as State Change to Work In Progress'.

2] Then with the help of scripting fetch the record from Table A and set the field phase to stock request.

   (To fetch the record of table A, there will be a one field which shows the relation between two table)


Let us know if you have any issue.
Thank you.

Also you can take help of below threads for scripting.
updating records of one table based on other 
Business rule to update field on another table / GlideRecord help 

 

OR could you please share Tables details or a field which is relate to table A to Table B.
Thank you

SAM321
Tera Contributor

@Sonu Parab can u provide related script, am new to scripting

 

Hi @SAM321 , Here I have shown one example similar to your requirement, you can make changes accordingly.
1] Business rule on Table B. (My table B is Incident and Table A is Problem.

Sonu_Parab_0-1678260828711.png

 

2] Script : Fetch record of Table A. (Here in my case Incident record is relate to the Problem record.)

Sonu_Parab_1-1678261023143.png

So once I changed the state of Incident record then using script it will fetch the perticular Table A record and it will update the field from table A.

Sonu_Parab_2-1678261397787.png

 

Thank you