Filtering substrings

MarkKs
Member Posts: 12
Hello, today I have a problem related with text input, here's the explanation:
Variables used:
gItemNo - Text 100
lRecItem2 - Record 24
Trigger: OnValidate - Page
What I have to do is simply, in the same field, write more than one product number without returning the error. After the END ELSE BEGIN
the missing code must filter each Item No. in something like this "12345678|12345678", the problem is that there can be more than one | and a lot of Item No. can be added...
I just need strategies to see this in another perspective, I don't want the rest of the code.
Variables used:
gItemNo - Text 100
lRecItem2 - Record 24
Trigger: OnValidate - Page
IF gItemNo <> '' THEN BEGIN IF STRPOS(gItemNo,'|') = 0 THEN BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",gItemNo); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END ELSE BEGIN END; END;
What I have to do is simply, in the same field, write more than one product number without returning the error. After the END ELSE BEGIN
the missing code must filter each Item No. in something like this "12345678|12345678", the problem is that there can be more than one | and a lot of Item No. can be added...
I just need strategies to see this in another perspective, I don't want the rest of the code.
0
Best Answer
-
Hey,
you could split the string with the help of .net.IF gItemNo <> '' THEN BEGIN IF STRPOS(gItemNo,'|') = 0 THEN BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",gItemNo); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END ELSE BEGIN SplitString(gItemNo,'|',ResultArray); FOR i := 0 TO ResultArray.Length - 1 DO BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",FORMAT(ResultArray.GetValue(i))); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END; END; END;
The SplitString Function is like this ...
Locals:TextToSplit DotNet System.String.'mscorlib DelimiterText DotNet System.String.'mscorlib
LOCAL SplitString(_StringToSplit : Text;_Delimiter : Text;VAR _ResultArray : DotNet "System.Array") TextToSplit := _StringToSplit; DelimiterText := _Delimiter; _ResultArray := TextToSplit.Split(DelimiterText.ToCharArray());
And you need also a Local in your caller segment to handle the result.ResultArray : DotNet "System.Array"
Hope this helps
EDIT
I guess you can delete this code too ... Split gives you the result in index 0 even if there is no delimiter. In your case the first item.IF STRPOS(gItemNo,'|') = 0 THEN BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",gItemNo); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END ELSE BEGIN
EDIT2
As you posted this in Classic Client section there might be a chance that you can not use .net
So here for this scenario. The result is a temporary item table and you can simply loop through this.
Locals:FoundText Text FoundPos Integer
LOCAL SplitStringWithoutDotNET(_TextToSplit : Text[100];_Delimiter : Text;VAR TmpItem : TEMPORARY Record Item) IF NOT TmpItem.ISTEMPORARY THEN ERROR('no good idea'); TmpItem.RESET; IF NOT TmpItem.ISEMPTY THEN TmpItem.DELETEALL; FoundPos := STRPOS(_TextToSplit,_Delimiter); WHILE (FoundPos <> 0) DO BEGIN FoundText := COPYSTR(_TextToSplit,1,FoundPos-1); _TextToSplit := COPYSTR(_TextToSplit,FoundPos+1); FoundPos := STRPOS(_TextToSplit,_Delimiter); IF (FoundText <> '') AND (NOT TmpItem.GET(FoundText)) THEN BEGIN TmpItem.INIT; TmpItem."No." := FoundText; TmpItem.INSERT; END; END; IF (_TextToSplit <> '') AND (NOT TmpItem.GET(_TextToSplit)) THEN BEGIN TmpItem.INIT; TmpItem."No." := _TextToSplit; TmpItem.INSERT; END;
5
Answers
-
Hey,
you could split the string with the help of .net.IF gItemNo <> '' THEN BEGIN IF STRPOS(gItemNo,'|') = 0 THEN BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",gItemNo); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END ELSE BEGIN SplitString(gItemNo,'|',ResultArray); FOR i := 0 TO ResultArray.Length - 1 DO BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",FORMAT(ResultArray.GetValue(i))); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END; END; END;
The SplitString Function is like this ...
Locals:TextToSplit DotNet System.String.'mscorlib DelimiterText DotNet System.String.'mscorlib
LOCAL SplitString(_StringToSplit : Text;_Delimiter : Text;VAR _ResultArray : DotNet "System.Array") TextToSplit := _StringToSplit; DelimiterText := _Delimiter; _ResultArray := TextToSplit.Split(DelimiterText.ToCharArray());
And you need also a Local in your caller segment to handle the result.ResultArray : DotNet "System.Array"
Hope this helps
EDIT
I guess you can delete this code too ... Split gives you the result in index 0 even if there is no delimiter. In your case the first item.IF STRPOS(gItemNo,'|') = 0 THEN BEGIN lRecItem2.RESET; lRecItem2.SETRANGE("Balance Code","Balance Code"); lRecItem2.SETRANGE("No.",gItemNo); IF NOT lRecItem2.FINDSET THEN ERROR(Text0001,gItemNo); END ELSE BEGIN
EDIT2
As you posted this in Classic Client section there might be a chance that you can not use .net
So here for this scenario. The result is a temporary item table and you can simply loop through this.
Locals:FoundText Text FoundPos Integer
LOCAL SplitStringWithoutDotNET(_TextToSplit : Text[100];_Delimiter : Text;VAR TmpItem : TEMPORARY Record Item) IF NOT TmpItem.ISTEMPORARY THEN ERROR('no good idea'); TmpItem.RESET; IF NOT TmpItem.ISEMPTY THEN TmpItem.DELETEALL; FoundPos := STRPOS(_TextToSplit,_Delimiter); WHILE (FoundPos <> 0) DO BEGIN FoundText := COPYSTR(_TextToSplit,1,FoundPos-1); _TextToSplit := COPYSTR(_TextToSplit,FoundPos+1); FoundPos := STRPOS(_TextToSplit,_Delimiter); IF (FoundText <> '') AND (NOT TmpItem.GET(FoundText)) THEN BEGIN TmpItem.INIT; TmpItem."No." := FoundText; TmpItem.INSERT; END; END; IF (_TextToSplit <> '') AND (NOT TmpItem.GET(_TextToSplit)) THEN BEGIN TmpItem.INIT; TmpItem."No." := _TextToSplit; TmpItem.INSERT; END;
5 -
Oh I was not expecting DotNet. But It worked, Thank you.
EDIT: Well both ways would work, Thank you again0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions