Buton code

Hello,

I wrote this very simple code in a javascript client side method :

var inn = aras.IomInnovator;
alert(this.getProperty("name"));
alert(this.getId());
alert("eee");

When i run this method  by a action in Server Event (in item Type Part for example)  , it's OK

But if I set this method to a button (event Onclick) in the Form Part,  i have the error :

Event handler failed with message: TypeError: this.getProperty is not a function

Why this difference ? 

 

 

  • Jeromecha,

    The issue is this. The "this" keyword changes meanings in different contexts, and in the context of an onClick event it doesn't refer to the item. Use document.thisItem instead to point at the thing the item whose form you're on, making your code look like the following:

    var inn = aras.IomInnovator;
    alert(document.thisItem.getProperty("name"));
    alert(document.thisItem.getId());
    alert("eee");

    In general, I don't trust code using the "this" keyword in different situations as it is very prone to meaning something other than what's expected. It's good to check what exactly "this" is at the time you're using it. (Also this is hard to write about without reenacting Abbot and Costello's Who's On First!) Hope that helps!

    -Skyler C