How to make two fields in sync/align with each other.

Pravallika14
Tera Contributor

Hello Team,

I have two fields "state" & "status" on a form. the value in state field should reflect in the other field .I want to sync /align  both the fields .

If I write a business rule/client script on "state" field , it should work on the "status" field as well & vice versa.

Kindly help me on this.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then you need to use before update BR

Condition: State Changes OR Status Changes

Script:

// sync the fields using if else

if(current.state.changes()){

	// sync state to status
	if(current.state == '1')
		current.status = '4';
	else if(current.state == '5')
		current.status = '6';

}
else if(current.status.changes()){

	// sync status to state
	if(current.status == '4')
		current.state = '1';
	else if(current.status == '6')
		current.state = '5';

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then you need to use before update BR

Condition: State Changes OR Status Changes

Script:

// sync the fields using if else

if(current.state.changes()){

	// sync state to status
	if(current.state == '1')
		current.status = '4';
	else if(current.state == '5')
		current.status = '6';

}
else if(current.status.changes()){

	// sync status to state
	if(current.status == '4')
		current.state = '1';
	else if(current.status == '6')
		current.state = '5';

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Pravallika14
Tera Contributor

Hi Ankur,

It worked, Thank you so much for your help!!

 

Regards,

Pravallika