Synchronous api.setState() in UI Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 12:25 AM - edited 01-05-2024 12:44 AM
Hi All,
I'd like to ask, whether anyone have experience with setting client state in UI builder but synchronously using callback function?
I'm trying to change state of client state but it always give me old value. I need that value to be up to date.
In ServiceNow documentation there's an example with the object but I need to implement that with simple boolean true false value.
Example from docs
UPDATED Funny behavior
any help would be appreciated.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 12:41 AM
Hi,
You can use simple statement.
api.setState('variable_name', 'value');
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 12:46 AM - edited 01-05-2024 12:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 03:54 AM - edited 06-24-2024 04:08 AM
The arrow function will get called after the execution of this script. You can verify this by adding debugger; statement in the arrow function.
This callback is to update the state parameter immediately after the execution of this script so that the updated value is available in the next codeflow.
Within this function, you can work with the source value that you are using to update the state parameter.
Refactor tip: updating currentValue is not required. Whatever this arrow function returns will be the new value of the state parameter. So you can just do: return result;