axMessageHandler how to move that to a variable?

Use this Forum to post your “How to …” questions about your use of aXes. This is not a technical support forum. Both the aXes Support Team at LANSA and other aXes customers may answer your questions. LANSA cannot guarantee the accuracy of any information posted by customers.

Moderator: jeanmichel

Post Reply
User avatar
Dino
Posts: 88
Joined: 19 May 2017, 08:29

axMessageHandler how to move that to a variable?

Post by Dino » 08 Feb 2022, 02:46

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:
msg01.jpg
msg01.jpg (104.27 KiB) Viewed 6507 times
msg02.jpg
msg02.jpg (70.35 KiB) Viewed 6507 times
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?
msg03.jpg
msg03.jpg (364.52 KiB) Viewed 6507 times
thank you

User avatar
Dino
Posts: 88
Joined: 19 May 2017, 08:29

Re: axMessageHandler how to move that to a variable?

Post by Dino » 10 Feb 2022, 00:54

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"
div3_2.jpg
div3_2.jpg (519.08 KiB) Viewed 6494 times
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.
div3_2s.jpg
div3_2s.jpg (329.51 KiB) Viewed 6494 times

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);
to get this final result:
div3_2x.jpg
div3_2x.jpg (138.75 KiB) Viewed 6494 times

tim mcentee
Posts: 37
Joined: 26 Jul 2017, 13:20

Re: axMessageHandler how to move that to a variable?

Post by tim mcentee » 11 Jan 2024, 14:32

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

Post Reply