CheckBox in Form

hi,

I added checkbox column to form. I would like that checkbox value(true or false) depands from x++ code. I want to check some condition and set true or false.

I tried to do that but without positive results.

I wrote edit method to display checkbox value. This good way ? How I should to do this?

edit NoYes editAcceptCartGroup(boolean Set, NoYes value)
{

NoYes ret = value;
;
if (value == NoYes::No)
{
ret = NoYes::Yes;
}
else
{
ret = NoYes::No;
}

return ret;

}

If you want just to show the value, use a display method instead. If you need to set values, use your edit method, but you have to implement some logic setting the value to some variable or so.

Look to other display/edit methods in AX and see also Form Classes and Methods [AX 2012], including the part about method caching.

BTW your current code can be rewritten as return !value; - that’s surely not what you intended.

In case I want to display checkbox (check or uncheck) depand on user group(user exist in group or not). After clicked in checkbox the group will be added to user or remove.

Could you write short description how I should to this it. Which method should I use?

Make a form with UserGroupInfo as a datasource. Add Id and Name fields (from UserGroupInfo) and a check with DataSource=UserGroupInfo and DataMethod=editIsMember.

Add the datasource’s method:

edit NoYes editIsMember(boolean _set, UserGroupInfo _userGroup, NoYes _value)
{
    if (_set)
    {
        if (_value)
        {
            //Add to group
        }
        else
        {
            //Remove from group
        }
    }
    else
    {
        return UserInfoHelp::userInUserGroup(curUserId(), _userGroup.Id);
    }
}

It’s quite straightforward.

_set says whether the value is being set (user ticked/unticked the checkbox)
_userGroup is the related UserGroupInfoRecord
_value is the new value of checkbox (use if _set is true)