web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

Grid filtering

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a job where I create a grid form by code.

Now I want to have the filter set.

Do I need to use the query I created?

I don't want this to be displayed first however.

My code.

static void Display_Users(Args _args)

{

//Initialization

UserInfo userInfo;

Query q;

QueryRun qr;

QueryBuildDataSource qbd;

QueryBuildRange qbr;

// form

DictTable dictTable;

Form form;

FormBuildDesign design;

FormBuildDataSource ds;

FormBuildActionPaneControl actionPane;

FormBuildActionPaneTabControl actionPaneTab;

FormBuildButtonGroupControl btngrp1;

FormBuildButtonGroupControl btngrp2;

FormBuildCommandButtonControl cmdNew;

FormBuildCommandButtonControl cmdDel;

FormBuildMenuButtonControl mbPosting;

FormBuildFunctionButtonControl mibPosting;

FormBuildFunctionButtonControl mibForecast;

FormBuildGridControl grid;

FormBuildGroupControl grpBody;

Args args;

FormRun formRun;

#Task dictTable = new DictTable(tableNum(userInfo));

// Do I really need the query?

q = new Query();

qbd = q.addDataSource(TableNum(userInfo));

qbr = qbd.addRange(FieldNum(userInfo, networkDomain));

qbr.value("=lex.local"); // Default operator is ==.

qbr = qbd.addRange(FieldNum(userInfo, company));

qbr.value("=BNO");

qbd.addSortField(FieldNum(userInfo, name));

qr = new QueryRun(q);

qr.prompt();

pause; //End of testing

form = new Form();

form.name("UserInfo");

ds = form.addDataSource(dictTable.name());

ds.table(dictTable.id());

design = form.addDesign('Design');

design.caption("User info");

design.style(FormStyle::SimpleList);

design.titleDatasource(ds.id());

actionPane = design.addControl( FormControlType::ActionPane, 'ActionPane');

actionPane.style(ActionPaneStyle::Strip);

actionPaneTab = actionPane.addControl( FormControlType::ActionPaneTab, 'ActionPaneTab');

btngrp1 = actionPaneTab.addControl( FormControlType::ButtonGroup, 'NewDeleteGroup');

btngrp2 = actionPaneTab.addControl( FormControlType::ButtonGroup, 'ButtonGroup');

cmdNew = btngrp1.addControl( FormControlType::CommandButton, 'NewButton');

cmdNew.buttonDisplay(FormButtonDisplay::TextAndImageLeft);

cmdNew.normalImage('11045');

cmdNew.imageLocation(SysImageLocation::EmbeddedResource);

cmdNew.primary(NoYes::Yes);

cmdNew.command(#taskNew);

cmdDel = btngrp1.addControl( FormControlType::CommandButton, 'NewButton');

cmdDel.text("Delete");

cmdDel.buttonDisplay(FormButtonDisplay::TextAndImageLeft);

cmdDel.normalImage('10121');

cmdDel.imageLocation(SysImageLocation::EmbeddedResource);

cmdDel.saveRecord(NoYes::Yes);

cmdDel.primary(NoYes::Yes);

cmdDel.command(#taskDeleteRecord);

mbPosting = btngrp2.addControl( FormControlType::MenuButton, 'MenuButtonPosting');

mbPosting.helpText("Set up related data for the group.");

mbPosting.text("Setup");

mibPosting = mbPosting.addControl( FormControlType::MenuFunctionButton, 'Posting');

mibPosting.text('Item posting');

mibPosting.saveRecord(NoYes::No);

mibPosting.dataSource(ds.id());

mibPosting.menuItemName(menuitemDisplayStr(InventPosting));

mibForecast = btngrp2.addControl( FormControlType::MenuFunctionButton, 'SalesForecast');

mibForecast.text('Forecast');

mibForecast.saveRecord(NoYes::No);

mibForecast.menuItemName( menuitemDisplayStr(ForecastSalesGroup));

grpBody = design.addControl(FormControlType::Group, 'Body');

grpBody.heightMode(FormHeight::ColumnHeight);

grpBody.columnspace(0);

grpBody.style(GroupStyle::BorderlessGridContainer);

grid = grpBody.addControl(FormControlType::Grid, "Grid");

grid.dataSource(ds.name());

grid.widthMode(FormWidth::ColumnWidth);

grid.heightMode(FormHeight::ColumnHeight);

// This is the filter I want directly when I enter the grid.

// UserInfo.company = "BNO";

// UserInfo.networkDomain = "lex.local";

//

grid.addDataField( ds.id(), fieldNum(UserInfo,name));

grid.addDataField( ds.id(), fieldNum(UserInfo,networkAlias));

grid.addDataField( ds.id(), fieldNum(UserInfo,id));

grid.addDataField( ds.id(), fieldNum(UserInfo,networkDomain));

grid.addDataField( ds.id(), fieldNum(UserInfo,company));

//grid.networkDomain("lex.local");

//grid.company = "BNO";

args = new Args();

args.object(form);

formRun = classFactory.formRunClass(args);

formRun.init();

formRun.run();

formRun.detach();

}

Please help.

Regards, Fredrik.

*This post is locked for comments

I have the same question (0)
  • Jonathan  Halland Profile Picture
    11,310 on at

    Fredrik I think you may need to explain first why you are creating such a complex form via code and not via a normal form design.

  • Community Member Profile Picture
    on at

    Hi,

    I don't want to design a form for this or create a class.

    The simplest way I could think of was by a job and code

    since this is a onetime deletion of users with a display

    and selection of some users, maybe not all (assume

    multiple delete is working).

    Fredrik.

  • Verified answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi Frederik.

    I'd recommend for your purposes to create a quick form. It should take a matter of minutes to create the form you want. You can then use the built in filtering and deleting on the form to accomplish what you want. Trying to accomplish this in code is very cumbersome with a full X++ custom form.

    As a note, I assume the users were created in error and dont have related data associated with them in the system yet. Otherwise you should just be disabling them

  • Community Member Profile Picture
    on at

    Hi Fredrik 999,

    Why not disable users instead of deletion for audit purposes...

  • Community Member Profile Picture
    on at

    The customer just want to delete them in AX, not AD since they are using the web-users.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans