Hi
If you add an axMessageHandler extension in aXes to the screen, you can capture things like for example when a user enters a decimal point in a numeric field that doesnt support it:
adding a name to that extension, and addTerminalMsg check makes it available in the screen, but how can you capture the value inside that to use for something else? I tried FIELDS("Mensaje").getValue() but that didn't work, most likely because is not just one string, but an array... so, how can you capture that value?
thank you
axMessageHandler how to move that to a variable?
Moderator: jeanmichel
Re: axMessageHandler how to move that to a variable?
Well, I decided to go in a different direction to get this value. As the divs and different tags are already identified, if you see the source of the screen using the "developer tools" in the browser, you can see the names of everything, and this section is called "terminalMessages"
So a script like this, can retrieve what is inside that tag, but because in this case the text returns with an <option> tag around it, I just used a little replace regex to remove the tags from it.
to get this final result:
So a script like this, can retrieve what is inside that tag, but because in this case the text returns with an <option> tag around it, I just used a little replace regex to remove the tags from it.
Code: Select all
/* Get what is inside element with id terminalMessages */
var terminalMessages =
document.getElementById('terminalMessages');
/* Remove the tags to have just the text */
var txtMessages =
terminalMessages.innerHTML.replace(/<\/?[^>]+(>|$)/g, "");
/* Now do whatever you want, assign it to field in the
screen, move to session storage, etc. */
alert("The terminal message says : " + txtMessages);
-
- Posts: 37
- Joined: 26 Jul 2017, 13:20
Re: axMessageHandler how to move that to a variable?
Hi Dino
Rather than mucking around with regex to strip the out html tags just use the object you created to find the children.
terminalMessages.children[0].innerHTML
or
terminalMessages.childNodes[0].innerHTML
If the messages are empty then there won't be any children so you would need to do a null check first.
If there are multiple messages then you could loop through the children to get each message. For multiple message using the regex will strip the html and the messages will be joined on one long string.
Tim
Rather than mucking around with regex to strip the out html tags just use the object you created to find the children.
terminalMessages.children[0].innerHTML
or
terminalMessages.childNodes[0].innerHTML
If the messages are empty then there won't be any children so you would need to do a null check first.
If there are multiple messages then you could loop through the children to get each message. For multiple message using the regex will strip the html and the messages will be joined on one long string.
Tim