Tuesday, February 10, 2009

How to call javascript functions from a custom menuitem

In the previous post we learned how to add custom menus. Now sometimes we need to call some custom functions for some information processing. So for that we can write a javascript function and call that javascript function from the MenuItem click.

for example: we added a MenuItem "Custom JavaScript function" at our desired entity location and wish to call our custom function Myfunction on MenuItem click
so we need to modify the ISV.config as mentioned below:


<MenuItem JavaScript="Myfunction()">
<Titles>
<Title LCID="1033" Text="Custom JavaScript function" />
</Titles>
</MenuItem>


Now place your function in the entity onload event and expose the Myfunction function to the page level e.g. this.Myfunction = Myfunction;


function Myfunction()
{
//Place Your logic Here...
}

this.Myfunction = Myfunction;




Now when you click on the MenuItem "Custom JavaScript function" the function Myfunction will be called.

No comments: