How to call screen action in Javascript in Javascript property in outsystem web?

Hi NaveenRaj,

In Traditional Web you can use one of these options to call a screen action from JS. And AFAIK you cannot trigger the screen actions from the Javascript property of the module.

One option is to use the FakeNotify web block from the RichWidgets module. This way you can use the following JS function to call the OnNotify screen action of the web block.

OsNotifyWidget('<FakeNotifyWidget>.Id', '<message>')

For more information check out this post.

An alternative, which I have not tried myself, is to use this Forge component to invoke web block events directly from JS. For more info check out this post and the instructions on how to use the component are on the Forge components' overview page.

Hope this helps.

Regards,

Nordin

Nordin Ahdi wrote:

Hi NaveenRaj,

In Traditional Web you can use one of these options to call a screen action from JS. And AFAIK you cannot trigger the screen actions from the Javascript property of the module.

One option is to use the FakeNotify web block from the RichWidgets module. This way you can use the following JS function to call the OnNotify screen action of the web block.

OsNotifyWidget('<FakeNotifyWidget>.Id', '<message>')

For more information check out this post.

An alternative, which I have not tried myself, is to use this Forge component to invoke web block events directly from JS. For more info check out this post and the instructions on how to use the component are on the Forge components' overview page.

Hope this helps.

Regards,

Nordin


Hi Nordin Ahdi,

                   Thanks for the response. I used FakeNotifyWidget and used OsNotifyWidget(....) inside JavaScript in JavaScript property of webblock. Its not working. So am trying with that Forge Component.

OsNotifyWidget('<FakeNotifyWidget>.Id', '<message>')



regards,

Naveen

NaveenRaj wrote:

How to call screen action in Javascript in Javascript property in outsystem web?

Hi NaveennRaj if you want to call an action from the JS use this

$(".SpecifiClassToTheButtonYouWantToCall").click();

Add this class to a hidden button and the destination of this button is the action you need


Cheers

Carlos Lessa

NaveenRaj wrote:

Hi Nordin Ahdi,

                   Thanks for the response. I used FakeNotifyWidget and used OsNotifyWidget(....) inside JavaScript in JavaScript property of webblock. Its not working. So am trying with that Forge Component.

OsNotifyWidget('<FakeNotifyWidget>.Id', '<message>')

regards,

Naveen

Hi Naveen,

Can you share an example OML with your implementation? I have used the FakeNotify widget in the past with success so I know for sure it works.

The steps are described in this post too.

Regards,

Nordin


Carlos Lessa wrote:

NaveenRaj wrote:

How to call screen action in Javascript in Javascript property in outsystem web?

Hi NaveennRaj if you want to call an action from the JS use this

$(".SpecifiClassToTheButtonYouWantToCall").click();

Add this class to a hidden button and the destination of this button is the action you need


Cheers

Carlos Lessa

Sorry I had a wrong understanding on this answer but you can also use it and combine if this method bellow

From the properties: declare a function and call it, check the pic


Call the action by invoking the function, in this case, I use the Extend property of a button to call it

and the result when I click

Cheers

Carlos Lessa

Nordin Ahdi wrote:

NaveenRaj wrote:

Hi Nordin Ahdi,

                   Thanks for the response. I used FakeNotifyWidget and used OsNotifyWidget(....) inside JavaScript in JavaScript property of webblock. Its not working. So am trying with that Forge Component.

OsNotifyWidget('<FakeNotifyWidget>.Id', '<message>')

regards,

Naveen

Hi Naveen,

Can you share an example OML with your implementation? I have used the FakeNotify widget in the past with success so I know for sure it works.

The steps are described in this post too.

Regards,

Nordin


Hi Nordin Ahdi,

                             Kindly find my sample attachment.


regards,

Naveen


Solution

Hi Naveen,

Please find a working example as an attachment. The below steps were followed:

  • The FakeNotify web block from RichWidgets is dragged directly to the screen. 
  • A name is given to that web block: "MyFakeNotifyWidget"
  • A new screen action was created from the OnNotify destination of the web block: "OnFakeNotify"
  • In the Preparation of the webscreen a RunJavascript action (from HTTPRequestHandler) was added with the following value in the script property:
    • "OsNotifyWidget('"+ MyFakeNotifyWidget.Id +"', 'A message from Javascript!')"
  • Inside the OnFakeNotify screen action a Deprecated_NotifyGetMessage action (from System module) is used to retrieve the message "A message from Javascript!" sent from JS function OsNotifyWidget()
  • A feedback message is used just after the Deprecated_NotifyGetMessage action the display a text and the retrieved message from JS.

Result: If you execute a request to that webscreen, a feedback message will be triggered directly with some text and the message sent from JS code.

Hope this helps!

Regards,

Nordin

Solution

Nordin Ahdi wrote:

Hi Naveen,

Please find a working example as an attachment. The below steps were followed:

  • The FakeNotify web block from RichWidgets is dragged directly to the screen. 
  • A name is given to that web block: "MyFakeNotifyWidget"
  • A new screen action was created from the OnNotify destination of the web block: "OnFakeNotify"
  • In the Preparation of the webscreen a RunJavascript action (from HTTPRequestHandler) was added with the following value in the script property:
    • "OsNotifyWidget('"+ MyFakeNotifyWidget.Id +"', 'A message from Javascript!')"
  • Inside the OnFakeNotify screen action a Deprecated_NotifyGetMessage action (from System module) is used to retrieve the message "A message from Javascript!" sent from JS function OsNotifyWidget()
  • A feedback message is used just after the Deprecated_NotifyGetMessage action the display a text and the retrieved message from JS.

Result: If you execute a request to that webscreen, a feedback message will be triggered directly with some text and the message sent from JS code.

Hope this helps!

Regards,

Nordin

Hi Nordin,

                 Thank you very much for your response..! Its working. 



regards,

Naveen


Carlos Lessa wrote:

NaveenRaj wrote:

How to call screen action in Javascript in Javascript property in outsystem web?

Hi NaveennRaj if you want to call an action from the JS use this

$(".SpecifiClassToTheButtonYouWantToCall").click();

Add this class to a hidden button and the destination of this button is the action you need


Cheers

Carlos Lessa


Hi Carlos Leesa,

                     I tried this way. It also working. Thank you very much. This is simple one.



regards,

Naveen

Hi Naveen,

Might I just add that Carlos' solution is indeed a simple one, but it is not considered a best practice to add inline Javascript. This must be avoided as much as possible.

You can read more about this here.

Regards,

Nordin

Nordin Ahdi wrote:

Hi Naveen,

Might I just add that Carlos' solution is indeed a simple one, but it is not considered a best practice to add inline Javascript. This must be avoided as much as possible.

You can read more about this here.

Regards,

Nordin


You are right, Anyway thank you guys for supporting me.

You're welcome Naveen. That is what we are here for.

Enjoy developing with OutSystems!