C/AL Code Filter Error w/ Equal Sign and Bracketing

headley27
Member Posts: 188
I need to filter a list of items using C/AL Code.
I have a problem where the code errors when an item containing an equal sign is filtered. The same error occurs with bracketing.
For example part number ABC123(v2) would fail.
This occurs when manually applying a filter as well.
I have found that surrounding the string with quotes 'ABC123(v2)' fixes the issue when applying the filter manually.
How do I pass quotes into my variable?
Rec = Current Record: Item Table
SKU = Record Variable (Stockkeeping Unit Table)
Code
FilterNo := Rec."No.";
SKU.SETFILTER("Item No.", FilterNo);
End Code
I need my FilterNo variable to work like this:
SKU.SETFILTER("Item No.", 'ABC123(v2)');
Not
SKU.SETFILTER("Item No.", ABC123(v2));
Can someone please guide me in the right direction?
Thank you,
headley27
I have a problem where the code errors when an item containing an equal sign is filtered. The same error occurs with bracketing.
For example part number ABC123(v2) would fail.
This occurs when manually applying a filter as well.
I have found that surrounding the string with quotes 'ABC123(v2)' fixes the issue when applying the filter manually.
How do I pass quotes into my variable?
Rec = Current Record: Item Table
SKU = Record Variable (Stockkeeping Unit Table)
Code
FilterNo := Rec."No.";
SKU.SETFILTER("Item No.", FilterNo);
End Code
I need my FilterNo variable to work like this:
SKU.SETFILTER("Item No.", 'ABC123(v2)');
Not
SKU.SETFILTER("Item No.", ABC123(v2));
Can someone please guide me in the right direction?
Thank you,
headley27
0
Comments
-
item.setfilter("No.",'''TEST(ITEM)''');
All ''' are three single quotes.
But how is this going to work if you have such special charecters in item no. ?? It will fail everywhere the item is used.LR0 -
The source of your problem is mis-using SETFILTER. YOu need to know that there is BIG difference between
SETFILTER(Field,'something');
andSETFILTER(Field,'%1','something');
The first one apply 'something' as filter (plain filter), second one apply string 'something' like value you want to filter... Please, use first option just only if you have some filter saved in variable and you want to apply this filter. In other cases use the second option or useSETRANGE(Field,Value);
if you are filtering for one value...0 -
Thank you kine.
That's exactly what I was looking for.
In the meantime, I had written some code to escape single quotes that existed in my variable. I then surrounded the variable with single quotes and passed it into the SetFilter function.
This worked for me using 7 lines of code but your solution gives me the same results using 1.
SKU.SETFILTER("Item No.",'%1',FilterNo);
Beautiful.
Thanks again,
headley270
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