when Assigned to changes from empty value then state should change to assigned state from open

anushadande1793
Tera Contributor

Hi 

 

Can anyone please help on the below query

 

Whenever Assigned to field changes from empty value then state field should automatically changes to Assigned state from open state. Can anyone please share scripting on how it can be achieved

 

Thank you

3 REPLIES 3

Nawal Singh
Giga Guru

Hi @anushadande1793 ,

 

You need to create client script-

 

Type- onChange

field- assigned-to

 

and you need to write down the as shown below-

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading) {
    return; // don't run on form load
  }

  // If Assigned to changes from empty to a value
  if (!oldValue && newValue) {
    // Set state to Open (value 1)
    g_form.setValue('state', '1');
  }
}

 

please test and let me know.

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh

AndersBGS
Tera Patron
Tera Patron

Hi @anushadande1793 ,

 

Instead of a client script as @Nawal Singh  suggested, I would go for a business rule instead based on the informed requirement. If state should update in browser, then a client script would be the right approach. If state should change server side, then a business rule is the right approach. 

 

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

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Ankur Bawiskar
Tera Patron
Tera Patron

@anushadande1793 

you can use before update BR on incident table

Condition: Assigned To changes AND Assigned to [IS NOT EMPTY]

Script:

current.state = '' ; // your state value here

If my response helped please mark it correct and close the thread so that it benefits future readers.

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