UIB api.setState Timing Issues
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 07:38 PM
I am aware that api.setState runs async, but it is limiting to not be able to use state in a way where you can count on timing so the value is what you think it should be by the time you, let's say, handle some event that maybe you emit AFTER the setState call. Anyone know of a way to run setState with a callback function that executes when the specified state param is updated?
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 07:56 AM
It's been almost a year and I still have issues with timing. Take this scenario that happens only intermittently:
- Input component on a page with a handler for "Input invalid set" to update clientState with the value (also does some minor validation on the field entry).
- Button component on the page with a handler for "Click" to save the field's value.
- User types in a value and then clicks on a custom button meant to save that value (and others). So the blur on the field that fires the "Input invalid set" event IS the click of the button.
- I can see state being updated, but by the time the client script handling the button click executes, the api.state value for that field is the previous value, not the new.
- This is not an uncommon user action. How can it be that you cannot rely on the input blur's updating of state being available when you access api.state behind the button click's event handler script?
@Brad Tilton or anyone at ServiceNow have any insight? Thx.