Dynamics User Group
Since 1995 - The Microsoft Dynamics Online User Community

count for Repeat, not until =......

rated by 0 users
This post has 9 Replies | 1 Follower

Top 50 Contributor
Male
Posts 395
Points 7,630
Member since 01-21-2007
stan Posted: 09-26-2007 12:27

could we made repeat not using until next := 0 BEGIN FINDFIRST; REPEAT GET("Entry No."); DELETE; UNTIL NEXT = 0; END; --> it delete all records for example I have 100 records and then I just want to delete 50 records so the other 50 are still exists could we delete them for count?

The True Test Of Man's Character Is What He Does When No One Is Watching....
  • | Post Points: 20
Top 50 Contributor
Male
Posts 343
Points 6,600
Member since 09-10-2001

I think You have to use a FOR - TO loop instead..

i := recordvar.count;
FOR j := 1 TO (i - 50) DO BEGIN
  IF j = 1 THEN
    recordvar.FINDFIRST
  ELSE
    recordvar.NEXT;
  recordvar.DELETE();
END;

(i & j are integer-variables)

But if You want to delete a number of records, why don't You set the appropriate filters, and then use DELETEALL() instead of looping?

Regards,

Alexander Pallesen
Freelance Navision Developer

"Life is a terminal disease that You just have to learn to live with"

Top 50 Contributor
Male
Posts 395
Points 7,630
Member since 01-21-2007

I'm using a little bit different
FOR j := 1 TO (Qty) DO BEGIN
IF j = 1 THEN
FINDFIRST
ELSE
NEXT;
DELETE();
END;
but it still won't worked :( qty variable is the count that i want to delete it
I have tried using delete all, but i didn't use setfilter, so all of my records deleted I used this and just modified for count

The True Test Of Man's Character Is What He Does When No One Is Watching....
  • | Post Points: 5
Top 50 Contributor
Male
Posts 395
Points 7,630
Member since 01-21-2007

 by the way could we do the setfilter for count?

SETFILTER("Entry No.",  "1..3");

--> like these for 3 records

but i want to setfilters without parameter "1..3", but 3 

The True Test Of Man's Character Is What He Does When No One Is Watching....
  • | Post Points: 20
Top 50 Contributor
Male
Posts 343
Points 6,600
Member since 09-10-2001

Hi Stan,

I'm a bit confused as to what Your intentions are but....

I think the reason why Your code desn't work, could be because there are some issues regarding the adressing of the record-variable.
I have tested the code, and it worked as it should in my database.
That might very well also be the reason why Your DELETEALL ended up deleting all records in the table.

A DELETEALL will delete all records in a given table, that falls inside filters You set.
So if the DELETEALL You tried to use, ended up deleting all records, that can only happen if no filters at all were set.

Regarding using SETFILTER for the count...
You can easily use the value You counted, as parameter in the SETFILTER, if that's what You ask.
But keep in mind that the value You counted (e.g. 50) not have any direct relation to the values of the records counted.
Say that You have counted 100 records, that does not mean that the records have "Entry No." 1 to 100, but could very well be 250 to 349 or what ever.
So I don't think that it is relevant to use the counted value directly in the SETFILTER.

However...
RecordVar.SETFILTER('1..%1',Qty) should do what You ask of.

If You at all times want 50 records to be left in the table, after You run the deletion-batch You're working on, then You could do something like this...
Record.SETFILTER(the filters needed);
Record.FINDLAST; // finds the very last record within the filter
Record.NEXT(-50); // jumps 50 rows back
EntryNoToFilterTo := Record."Entry No." - 1;

Then do a
RecordVar.SETFILTER('1..%1',EntryNoToFilterTo);
RecordVar.DELETEALL();

EntryNoToFilterTo is a integer-variable.
I assume that DataType of "Entry No." is Integer as well.

 

Regards,

Alexander Pallesen
Freelance Navision Developer

"Life is a terminal disease that You just have to learn to live with"

  • | Post Points: 70
Top 10 Contributor
Male
Posts 1,363
Points 17,805
Member since 01-23-2004
DynamicsNAVMVP

I'd like to suggest to the both of you to read about FINDFIRST and FINDLAST, because neither one of you seem to understand what it does.

These t

wo
  • | Post Points: 5
Top 10 Contributor
Male
Posts 1,363
Points 17,805
Member since 01-23-2004
DynamicsNAVMVP

I'd like to suggest to the both of you to read about FINDFIRST and FINDLAST, because neither one of you seem to understand what it does.

These t

  • | Post Points: 20
Top 50 Contributor
Male
Posts 395
Points 7,630
Member since 01-21-2007

 hmmmmm

sure , your code is magnificent

at last i successfully generate it

yesterday i failed just because i wrong put in the trigger

heheh

thank you very much sander :) 

The True Test Of Man's Character Is What He Does When No One Is Watching....
  • | Post Points: 5
Top 50 Contributor
Male
Posts 343
Points 6,600
Member since 09-10-2001

DenSter:

I'd like to suggest to the both of you to read about FINDFIRST and FINDLAST, because neither one of you seem to understand what it does.

Hi Daniel,

Well the learning-curve never becomes horizontal... Smile

So the problem here is that I use a FINDFIRST/FINDLAST in combination with a NEXT?
Instead I should have used FINDSET and FIND('+')?

Or am I totally missing the point here?

 

Regards,

Alexander Pallesen
Freelance Navision Developer

"Life is a terminal disease that You just have to learn to live with"

  • | Post Points: 20
Top 10 Contributor
Male
Posts 1,363
Points 17,805
Member since 01-23-2004
DynamicsNAVMVP

Yes the FINDFIRST and FINDLAST commands are intended to be used to retrieve only one record. If you need to loop through a set of records, you use FINDSET. Read the F1 help for these commands, like I suggested, and you will learn what they are supposed to be used for.

  • | Post Points: 5
Page 1 of 1 (10 items) | RSS


Copyright Dynamics User Group, 1995-2009, all rights reserved. The Dynamics User Group is not affiliated with Microsoft Corporation.