views:

690

answers:

1

The Dynamics AX 2009 Best Practice add-in is throwing the following error on a display method override.

"TwC: Validate access to return value from the display/edit method."

Here is my display method.

display ABC_StyleName lookupModuleName(ABC_StyleSettings _ABC_StyleSettings)
{
    ;
return ABC_Styles::find(_ABC_StyleSettings.StyleID).StyleName;
}

I'm assuming it wants me to check a config or security key before returning a result. Any suggestions/examples on where to start?

Thanks

+1  A: 

This is a reminder that you need to consider whether the user should have access to the data you are returning from the function. For table fields, the kernel normally does this for you based on the security groups the user is in and the security keys set on fields.

To check if a user has access to a field, use the hasFieldAccess function. To see how this is used, look at the table methods BankAccountStatement.openingBalance() or CustTable.openInvoiceBalanceMST(). There are other helper functions to check security keys such as hasMenuItemAccess, hasSecuritykeyAccess, and hasTableAccess.

In your case, add this code:

if(!hasFieldAccess(tablenum(ABC_Styles),fieldnum(ABC_Styles,StyleName)))
{
    throw error("@SYS57330");
}

Even after you add that code, you will still get the Best Practice error. To tell the compiler you have addressed the issue, you need to add the following comment immediatly before the function declaration:

//BP Deviation Documented
Jay Hofacker
I've seen your name on a few of my questions. Thanks for taking time to help out the new guy. It's been a painful transition from .NET to X++, but I'm getting there. ;)
Brad