Saturday, August 25, 2007

Display method in code

Scenario: Can i use display methods in X++ code. I mean if i have a display method getStatus() on table Vend. I can use it like vend.getStatus(). Is it a violation of best practice what are the pros and cons.

Answer: No, there is no performance penalty and no best practice warning is issued.
So you can go ahead and use the display methods in code.
The only difference from a non-display method is that you can actually use them in forms and reports.

Snippet:
Add as display method getStatus() in the CustTabl method list.

public display boolean getStatus()
{
return true;
}

Use this method in the field group and in the code simultaneously.

public void processCustomerStatus()
{
if (this.getStatus())
{
this.write();
}
else
{
info("Consider status");
}
}

4 comments:

  1. But you wouldn't create a display method solely for the purpose of using it in code, would you?

    ReplyDelete
  2. Actually we normally create display methods just for Display purpose, but there no issue using them in code.

    ReplyDelete
  3. Ok fine ... I get it. Other than performance issues, I guess theres nothing wrong with that.

    ReplyDelete
  4. is there a way to invoke display methods using reflection apis?
    I'd like to, using reflection, invoke a datasource display method from the form and get the result in my x++ code, is that possible?
    ex: suppose you have a form that has one column as a result of a display method, I would like to make sum of the result in a programmatically way.
    Thank you so much in advance!

    ReplyDelete