Loop through grid columns in runtime in AX 2012 - grid

I want to loop through columns(fields) in grid control in AX 2012 form. I have this logic to loop through fields :
static void Job1(Args _args)
{
SysDictTable dictTable = new SysDictTable(tableNum(PurchLine));
SysDictField dictField;
TreeNode treeNode;
FieldId fieldId = dictTable.fieldNext(0);
while (fieldId)
{
dictField = dictTable.fieldObject(fieldId);
if (dictField.isSql() && !dictField.isSystem())
{
treeNode = dictField.treeNode();
info(strFmt("%1 | %2 | %3",
dictField.name(), // Field name
treeNode.AOTgetProperty("Label"), // Label id
SysLabel::labelId2String(treeNode.AOTgetProperty("Label")))); // Label string
}
fieldId = dictTable.fieldNext(fieldId);
}
}
This loop through table, I need similar logic to loop through grid fields but in RUNTIME.
For example if grid data source has 5 columns and 3 are removed in UI, i want to loop just through these 2 that are left in the grid.
So my question is how to get grid fields in runtime( not from datasource table) ?

The below assumes your grid is named "GridOverview". You call it like:
::outputGridControls(element) where element is your form.
public static void outputGridControls(FormRun _formRun)
{
int i;
FormGridControl formGridControl;
FormControl formControl;
formGridControl = _formRun.control(_formRun.controlId(identifierStr(GridOverview)));
if (formGridControl)
{
for (i=1; i<=formGridControl.controlCount(); i++)
{
formControl = formGridControl.controlNum(i);
if (formControl && formControl.visible())
{
info(strFmt("%1 (%2)", formControl.name(), formControl.labelText()));
}
}
}
}
What you're doing above is reflecting on the AOT table, but you need to be looking at the FormRun and not the actual table or even the DataSource.

Related

How to find all tables using a defined EDT?

How does one create a job which finds all tables containing a particular extended data type?
I found this JOB, but it gives me an error: https://fredshen.wordpress.com/2006/02/05/find-out-tables-containing-specific-edt/
Use the Cross Reference Tool.
It will show code uses as well.
try this:
static void findEdtinTable(Args _args)
{
treeNode childNode;
treeNode fields;
treenodeIterator it, itFld;
str properties;
str table;
str field;
str extendedDataType;
str searchType = "PurchInternalInvoiceId"; // EDT
int x;
treeNode t = TreeNode::findNode('\\Data Dictionary\\Tables');
it = t.AOTiterator();
childNode= it.next();
while (childNode)
{
Table = childNode.treeNodeName();
itFld = t.AOTfindChild(childNode.treeNodeName()).AOTfindChild("Fields").AOTiterator();
fields = itFld.next();
while (fields)
{
field = fields.treeNodeName();
properties = fields.AOTgetProperties();
extendedDataType = findProperty(properties, "ExtendedDataType");
if (extendedDataType == searchType)
{
info(strfmt("%1 / %2 – ExtendedDataType: %3", table, field, extendedDataType));
}
fields = itFld.next();
}
childNode= it.next();
}
}

make a dynamic tableview javaFX editable

I'm trying to make editable a table view dynamic in javaFX, i already have the dynamic table loading values from a object and works perfect, but i can't make this editable.
i create the dinamic table with this
ArrayList<reportes> rs = BD.ConsultarVarios(selecionado);
for (int column = 1; column +1< rs.size(); column++) {
tablevarios.getColumns().add(
createColumn(column, rs.get(column).getNombre()));
}
// Add data to table:
ArrayList<ObservableList<StringProperty>> data = new ArrayList<>(FXCollections.observableArrayList());
for (int i = 0; rs.get(0).getValor().size() > i; i++) {
ObservableList<StringProperty> data2 = FXCollections.observableArrayList();
for (int k = 0; rs.size() > k+1; k++) {
data2.add(new SimpleStringProperty(rs.get(k).getValor().get(i)));
}
data.add(data2);
tablevarios.getItems().add(data.get(i));
}
but when i try to make editable with this
tablevarios.getColumns().get(i).setCellFactory(column -> new EditCell());
i have this error from the console
Error:(1687, 78) java: incompatible types: bad return type in lambda expression
sample.Main.EditCell cannot be converted to javafx.scene.control.TableCell,capture#1 of ?>
thanks for the help
Does your EditCell extends ListCell ?
I did it in my project like this:
class EditCell extends ListCell<?> {
// your cell properties here
#Override
protected void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
}
tablevarios.getColumns().get(i).setCellFactory(lv -> {
ListCell<?> cell = new EditCell();
//maybe add context menu to cell or other thins
return cell;
}

Getting gridview data in variables and inserting it to database

I am making a shopping cart type of thing using grid view user will keep adding item in it after doing it so user will click save i want to get values from all columns of grid view each row at a time and save it to database.
here is the code for grid view load
protected void add_Click(object sender, EventArgs e)
{
product.Item = Item_Drop.SelectedItem.Text;
product.Quantity = quantity_box.Text;
int qun =Convert.ToInt32(quantity_box.Text);
int unitP= Convert.ToInt32(unitPrice_box.Text);
product.item_Toal = (qun*unitP).ToString();
list.Add(product);
temp_gridView.DataSource = list;
temp_gridView.DataBind();
}
And here is what i am trying to get values
public void Values_from_grid()
{
foreach(temp_gridView row in temp_gridView.Rows)
{
for(int i = 0; i < temp_gridView.Columns.Count, i++)
{
String header = temp_gridView.Columns[i].HeaderText;
String cellText = row.Cells[i].Text;
}
}
}
i am not getting any values in "header" or "cellText" . .. .
Use this code to get header row value .
GridViewName.HeaderRow.Cells[0].Text;
Found Answer no need to use
GridView.Rows.Count
just use a simple int to iterate
int i = 0;
foreach(GridViewRow row in temp_gridView.Rows)
{
box.Item_id = temp_gridView.Rows[i].Cells[0].Text;
box.Quantity = temp_gridView.Rows[i].Cells[1].Text;
box.Total = temp_gridView.Rows[i].Cells[2].Text;
i++;
}

Dynamics AX 2009: How to programmatically allowEdit on Checkbox control

Essentially, this is what I'm faced with:
I want to modify the InventTrans form
By default, it has the entire InventTrans datasource set to AllowEdit = No
I want to enable editing on ONE new Enum field (NoYes type)
Should I set the InventTrans datasource to AllowEdit = Yes and then painfully change 40+ fields in the datasource to be AllowEdit = No, OR is there a way to programmatically iterate through the fields of the datasource and set this property by name? (Please say there is, or an equally easy way to do this!)
Thanks in advance!
This is how I would try to disable editing to all fields:
DictTable dictTable;
DictField dictField;
int fldCnt;
;
dictTable = new DictTable(tablenum(InventTrans));
for (fldCnt = 1; fldCnt <= dictTable.fieldCnt() ; fldCnt++)
{
dictField = new DictField(tablenum(InventTrans), dictTable.fieldCnt2Id(fldCnt));
info(strfmt("%1", dictField.id(),dictField.name()));
InventTrans_DS.object(dictField.id()).allowEdit(false);
}
EDIT: Better approach to iterate through form's DS'es fields only:
DictTable dictTable;
DictField dictField;
int fldCnt;
QueryBuildFieldList qBFL;
;
qBFL = InventTrans_DS.query().dataSourceTable(tablenum(InventTrans)).fields();
for (fldCnt = 1; fldCnt <= qBFL.fieldCount() ; fldCnt++)
{
dictField = new DictField(tablenum(InventTrans), qBFL.field(fldCnt));
info(strfmt("%1 %2 ", dictField.id(),dictField.name()));
if(InventTrans_DS.object(qBFL.field(fldCnt))) //exception recVersion for example
{
InventTrans_DS.object(qBFL.field(fldCnt)).allowEdit(false);
}
}
I have a scenario in which I want to allow editing of ItemID in the InventJournalTrans form, based on an enum value in ANOTHER form. Is this possible?
Can args() class(parm method) be used to fetch the value of the checkbox? along with on the below condition in the active()?
My codes:
public int active()
{
int ret;
;
ret = super();
if([datasource table name].[Column 1 field name] == [Column1 value to
deactivate Column 3])
{
[datasource table name]_ds.object(fieldNum([datasource table name],
[Column 1 field name])).allowEdit(false);
}
else
{
[datasource table name]_ds.object(fieldNum([datasource table name],
[Column 1 field name])).allowEdit(true);
}
return ret;
}

how to read each value of a column in a table

Using x++ how to create a job to read each value of a column in a table in Microsoft dynamics AX 2009?
This code will display all the column values for a record.
static void Job1(Args _args)
{
DictTable dictTable = new DictTable(tableNum(CustTable));
DictField dictField;
int counter, fieldId;
CustTable custTable;
anytype value;
select firstonly custTable;
for (counter = 1; counter <= dictTable.fieldCnt(); counter++)
{
fieldId = dictTable.fieldCnt2Id(counter);
dictField = new DictField(tableNum(CustTable), fieldId);
if (!dictField.isSystem())
{
value = custTable.(fieldId);
if(value)
{
info(strFmt('%1 = %2',
dictField.label(),
any2str(value)));
}
}
}
}
For getting all the values for a specific column, please use Carlos Heuberger's code.
One possibility: in the AOT (Ctrl-D) right-click on Jobs and select New Job. In the new window enter something like (using the correct table and column name you want to read):
static void Job()
{
YourTable yourTable;
;
while select TheColumn from yourTable
{
// process yourTable.TheColumn
info(strFmt("value: %1", yourTable.TheColumn));
}
}
but thera are some other ways: Select Statements
Just a slight mod, took out any2str to make my table work:
strFmt('%1 = %2 \r\n', dictField.label(), value);

Resources