While Select in Ax

Here i have a big problem to complete my task

i have a table in that i need to update the row by sequence but when im using this code its not working

Tablename obj;
while select obj
{
info(strfmt(" before weekno is: %1",obj.Number));

}

in this table i have the number in sequence but when i printing the values using this while select its printing the value by shuffle manner

could u help me please???

You can use “orderby” in your code to arrange it in sequence.

If you want it in descending order just use “order by desc” or if you want it in ascending order just use “order by” only.

Tablename obj;

while select obj order by Number

{
info(strfmt(" before weekno is: %1",obj.Number));

}

Use the above code. Hope it helps.

thank u raja its working but in my table that number is not unique one so if im using this “order by” its gave in some arragement

so can u please explain how the while select is working

Hello,

It is not clear what the issue is.

If you want to order by records in table, in this case use ‘recId’ field.

Also you have to use the reserved keyword ‘forupdate’ in your while select statement.

Thank u harish Now i clear by ur reply

but i doubt is there

how can i create my own identity column with auto generating number from 1-1000 in table like we used in SQL?

Can u tell me the exact requirement ?

Do u want to update all the records or do u need only the numbers in proper order without duplication?

i have the table called week master in that i have

status,weeknumber,startdate,End date

if the weeknumber of today’s is equal to weeknumber on the table means the status is active

else lesser means its close else grearter staus is open

here my task is when i press the button in form i need to change the status which is in active to close and next row status value should be Active

for this only i asked about while select

is this clear for u or not? Now can u help me???

i have the table called week master in that i have

status,weeknumber,startdate,End date

if the weeknumber of today’s is equal to weeknumber on the table means the status is active

else lesser means its close else grearter staus is open

here my task is when i press the button in form i need to change the status which is in active to close and next row status value should be Active

for this only i asked about while select

is this clear for u or not? Now can u help me??? raja

In this case, u need not to use while select statement. Better use two separate select statements for update.

select forupdate tablename where tablename.status == enum::active;

tablename.status = close;

tablename.clear();

select firstonly forupdate tablename order by recId where table.status == open;

tablename.status = active;

(You can use the second update in the above code if you want the first record with open status or else use your own logic for fetching the proper record)

Try this format.

In this case, u need not to use while select statement. Better use two separate select statements for update.

select forupdate tablename where tablename.status == enum::active;

tablename.status = close;

tablename.clear();

select firstonly forupdate tablename order by recId where table.status == open;

tablename.status = active;

(You can use the second update in the above code if you want the first record with open status or else use your own logic for fetching the proper record)

Try this format.

Thank u very much Raja its working

Ur Such a Talented guy Pa…

Thank u Keep in touch…

Hi Manimaran,

Thank you, just verify the solution if you got the expected result.