Discussion:
Field Id for Form Control
(too old to reply)
Anna Petersen
2007-03-02 16:43:29 UTC
Permalink
Hello,

I am needing to retrieve the field id from a form. I have access to the
following objects in my section of code: the FormRun, the FormStringControl,
and the FormBuildStringControl.

I am trying to check the mandatory status of a field which in this case is
being set at the DataSource level and not the control level. I was trying to
create a new SysDictField to retreive the information but the id's I get back
from control.datasource() and control.datafield() appear to point to
temporary table in memory(??)

Any help at all that anyone could offer would be greatly appreciated. I feel
like I have hit a brick wall here. I can get the correct tableid using the
following:

formRun.form().dataSource(control.dataSource());

but I have no idea how to get the correct field id for the control.

Thank you!
Max Belugin
2007-03-02 19:57:58 UTC
Permalink
AFAIR there the classes you have mentioned have dataField and dataMethod
property methods. So just use them.
Post by Anna Petersen
but I have no idea how to get the correct field id for the control.
--
http://axcoder.blogspot.com
http://belugin.info/sidax - freeware sidebar for Axapta (Dynamics Ax)
Anna Petersen
2007-03-02 22:40:00 UTC
Permalink
The dataField and dataSource methods on form controls return table ids and
field ids that like I said I think point to some kind of temporary object in
memory or something.

When I try the following the SysDictField object is never initialized I
assume because these are not "valid" lookup ids.

(control is an instance of FormStringControl in the following code excerpts)

int tableID;
fieldid fieldID;
SysDictField sysdictField;
boolean isMandatoryAtDSLevel;
;

tableID = control.dataSource();
fieldID = control.dataField();

sysDictField = new SysDictField(dsTableId, dsFieldId);
isMandatoryAtDSLevel = sysDictField.mandatory();

At the last line above it exceptions saying that the object has not been
initialized. I assume because the ids are not the right ones to feed to
SysDictField.

If I am doing something wrong, please let me know :)

Thanks





control
Post by Max Belugin
AFAIR there the classes you have mentioned have dataField and dataMethod
property methods. So just use them.
Post by Anna Petersen
but I have no idea how to get the correct field id for the control.
--
http://axcoder.blogspot.com
http://belugin.info/sidax - freeware sidebar for Axapta (Dynamics Ax)
Anna Petersen
2007-03-02 23:12:40 UTC
Permalink
Maybe it will help if I provide the complete method with the two ways I have
tried to get the information I need:

boolean isRequired()
{
boolean controlLevel, dataSourceLevel;
SysDictField sysDictField, controlDictField;
FormBuildDataSource formBuildDataSource;
int dsTableId, controlTableId;
fieldid dsFieldId, controlFieldId;
;

controlLevel = control.mandatory();

controlTableId = control.dataSource();
controlFieldId = control.dataField();
controlDictField = new SysDictField(controlTableId, controlFieldId);

formBuildDataSource = formRun.form().dataSource(control.dataSource());
dsTableId = formBuildDataSource.table();
dsFieldId = fieldExt2id(control.dataField());
sysDictField = new SysDictField(dsTableId, dsFieldId);
dataSourceLevel = sysDictField.mandatory();

return controlLevel || dataSourceLevel;
}

When debugging the above the controlDictField object is null. The
sysDictField object is initialized but I beleive it reflects the setting in
the CustTable in the DataDictionary and not the CustTable in the CustTable
form. If that makes sense. I can cleary see that the property on the
CustTable form datasource field is set to mandatory in the test case I am
debugging but the same field in the DataDictionary CustTable is not set to
mandatory.
Post by Anna Petersen
The dataField and dataSource methods on form controls return table ids and
field ids that like I said I think point to some kind of temporary object in
memory or something.
When I try the following the SysDictField object is never initialized I
assume because these are not "valid" lookup ids.
(control is an instance of FormStringControl in the following code excerpts)
int tableID;
fieldid fieldID;
SysDictField sysdictField;
boolean isMandatoryAtDSLevel;
;
tableID = control.dataSource();
fieldID = control.dataField();
sysDictField = new SysDictField(dsTableId, dsFieldId);
isMandatoryAtDSLevel = sysDictField.mandatory();
At the last line above it exceptions saying that the object has not been
initialized. I assume because the ids are not the right ones to feed to
SysDictField.
If I am doing something wrong, please let me know :)
Thanks
control
Post by Max Belugin
AFAIR there the classes you have mentioned have dataField and dataMethod
property methods. So just use them.
Post by Anna Petersen
but I have no idea how to get the correct field id for the control.
--
http://axcoder.blogspot.com
http://belugin.info/sidax - freeware sidebar for Axapta (Dynamics Ax)
Anna Petersen
2007-03-02 23:16:09 UTC
Permalink
Assuming the ids I get from the control dataSource and dataField methods
could lead me back to the mandatory property of the data field, how would I
go about doing this? I can't seem to use SysDictField as this is expecting a
different id. Is there some way to grab the instance of the field for the
form to check the mandatory setting?


Any help would be appreciated!
Post by Anna Petersen
The dataField and dataSource methods on form controls return table ids and
field ids that like I said I think point to some kind of temporary object in
memory or something.
When I try the following the SysDictField object is never initialized I
assume because these are not "valid" lookup ids.
(control is an instance of FormStringControl in the following code excerpts)
int tableID;
fieldid fieldID;
SysDictField sysdictField;
boolean isMandatoryAtDSLevel;
;
tableID = control.dataSource();
fieldID = control.dataField();
sysDictField = new SysDictField(dsTableId, dsFieldId);
isMandatoryAtDSLevel = sysDictField.mandatory();
At the last line above it exceptions saying that the object has not been
initialized. I assume because the ids are not the right ones to feed to
SysDictField.
If I am doing something wrong, please let me know :)
Thanks
control
Post by Max Belugin
AFAIR there the classes you have mentioned have dataField and dataMethod
property methods. So just use them.
Post by Anna Petersen
but I have no idea how to get the correct field id for the control.
--
http://axcoder.blogspot.com
http://belugin.info/sidax - freeware sidebar for Axapta (Dynamics Ax)
hOObsy
2007-03-05 13:39:33 UTC
Permalink
Hi Anna!

Some day I had to figure out the mandatory fields of a form. I used a static
method in a Tools class. Maybe this is the chunk of info you where looking
for!

static boolean checkFillMandatoryFDS(FormDataSource fds)
{
DictTable dictTable = new DictTable(fds.table());
Common cursor = fds.cursor();
int i;
FieldId fieldId;
boolean res = true;
;

for( i = 1; i <= dictTable.fieldCnt(); i++ )
{
fieldId = dictTable.fieldCnt2Id(i);
if((! dictTable.fieldObject(fieldId).isSystem()) &&
fds.object(fieldId).mandatory() && ! cursor.(fieldId))
{
if(! checkFailed(strFmt("@SYS26332",
dictTable.fieldObject(fieldId).label())))
res = false;
}
}
return res;
}

good luck!
unknown
2007-03-03 07:45:00 UTC
Permalink
Hello, Anna.

The solution is to use the Object method of the formDataSource class:

boolean isRequired()
{
boolean controlLevel, dataSourceLevel;
FormDataObject fieldObj;
;

controlLevel = control.mandatory();

fieldObj = formRun.dataSource().object(control.dataField());
dataSourceLevel = fieldObj.mandatory();

return controlLevel || dataSourceLevel;
}

if you do not have the formDataSource object, but can get the
FormBuildDataSource, you can try getting the first one the following way:

formBuildDataSource = formRun.form().dataSource(control.dataSource());
fieldObj =
formRun.dataSource(formBuildDataSource.name()).object(control.dataField());

Good luck!
--
Kashperuk Ivan (Vanya), MCP
My blog - http://kashperuk.blogspot.com
Post by Anna Petersen
Hello,
but I have no idea how to get the correct field id for the control.
Thank you!
Anna Petersen
2007-03-05 15:19:53 UTC
Permalink
Oh thank you thank you!! Your solution was perfect!! I think I tried
something akin to that but I was trying to use the dataSource off the form.

Your way was short, sweet, and worked like a charm. Thank you very much :)
Post by unknown
Hello, Anna.
boolean isRequired()
{
boolean controlLevel, dataSourceLevel;
FormDataObject fieldObj;
;
controlLevel = control.mandatory();
fieldObj = formRun.dataSource().object(control.dataField());
dataSourceLevel = fieldObj.mandatory();
return controlLevel || dataSourceLevel;
}
if you do not have the formDataSource object, but can get the
formBuildDataSource = formRun.form().dataSource(control.dataSource());
fieldObj =
formRun.dataSource(formBuildDataSource.name()).object(control.dataField());
Good luck!
--
Kashperuk Ivan (Vanya), MCP
My blog - http://kashperuk.blogspot.com
Post by Anna Petersen
Hello,
but I have no idea how to get the correct field id for the control.
Thank you!
Continue reading on narkive:
Loading...