could we Use variable (boolean) as SETRANGE

could we use variable that we create through C/AL Global as setrange?

i want to delete first character that a variable named “DelPrefix” have value = true

I Have table “SN” with the field : Serial No ,Item No., Part No.,Entry No. (PK)

In Form SN, i add variable DelPrefix (Boolean)

and i want if user give tickmark (value true) so the Serial No. will delete it’s first character

for example if current SN = SGH1234567, after execute it will be GH1234567

my code push trigger :

SN.GET(“Entry No.”);

SN.“Serial No.” := DELSTR(“Serial No.”,1,1);

SN.MODIFY

→ It works if we do it one by one

could any of you help me

thanx for the answer

Well I’m not quite sure where the SETRANGE comes in here!

But if you plan is to change all your serial numbers then the way is to do it one by one, ex. in a REPEAT UNTIL loop.

Stan,

As I understand, you want to check several entries and then run function which updates prefixe for checked records.

You can’t filter on variable, because it is not saved in DB for each record. You can use temporary record for that - when you check “DelPrefix”, you insert selected record to temporary, in case of uncheck, you delete corresponding temp record. On push button you can go through temporary records and update corresponding real records.

nope… i change my mind i add field boolean named “Prefix” and then i add code like this SETRANGE(Prefix,TRUE); IF FINDSET THEN BEGIN FINDFIRST; REPEAT GET(“Entry No.”); “Serial No.” := DELSTR(“Serial No.”,1, 1); MODIFY; UNTIL NEXT = 0; END; RESET; the problem had solved thanx :slight_smile:

Hi Stan,

In your code fragment:

SETRANGE(Prefix,TRUE);

IF FINDSET THEN BEGIN

FINDFIRST;

REPEAT

GET(“Entry No.”);

“Serial No.” := DELSTR(“Serial No.”,1, 1);

MODIFY;

UNTIL NEXT = 0;

END;

RESET

…you do not need the FINDFIRST because the FINDSET will retrieve the first record anyway. You should also consider using FINDSET(TRUE, FALSE). This indicates that your a performing an update on the records in your set (the first TRUE parameter), but that you are not updating the primary key (the second FALSE parameter). It will give a more efficient read/update loop against SQL Server; even if code that you write now is not targeting this platform, it may do in the future.

Dean.

OK thanx a lot Dean :slight_smile: