Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

SAM321
Tera Contributor

@Sonu Parab Table A field name is Phase 

                         Table B field name is State

when table B State field is selected and saved as work in progress , Table A Phase field should be changed to stock request and saved

Table B

Screenshot (96).png

Table A

Screenshot (97).png

Thank you for the snippet. Is there a field which shows the relationship between two table?

 

 

SAM321
Tera Contributor

@Sonu Parab yes there is Reference field (Procurement number) in table B,  which is the reference of Table A.(procurement table)

@SAM321 okay. Then you can take help of above solution which I have shared in same thread.
Create the a BR and do script in it.
Let us know if any issue occur.

 

Thank you

@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