I need to change the value of a textarea field (that has the control of fieldControl-text-box-text), but I am running into issues.
As context, I am trying to do the change via a browser extension - so I don't have access to the form context.
Here is what I am doing:
1. If the field is focused, I insert the content directly (textareaElement.value = newContent).
2. If the field is not focused, I am using the Xrm.Page API (Xrm.Page.getAttribute(fieldName).setValue(newContent))
While this strategy works most of the time, it doesn't in 1 out of 10 cases.
These mainly happen when the field is not focused - when using the Xrm API.
In these cases, the textarea gets the new value (so Xrm.Page.getAttribute(fieldName).getValue() returns the proper new content) but then gets reverted after some milliseconds.
I have a way of detecting it - a timeout that checks after 100ms if the content is still the one I want, but no solution on how to fix it.
These reverts happen in the following situation: the user clicks on a word, and the focus is moved to a new area from which he clicks some text to replace the word.
Do you have any idea what I'm doing wrong?
Is there some period when all updates to the textarea get reverted?
Do I need to do some extra step after setValue?