How stop filter when add new customer because not increment

ahmedbaahmedba Member Posts: 424
Hi guys i have problem i make filtration to customer card to see specified location as jed(there are three branches (jed-mak-rab) when i make filter i using filter group and write the following code in open form trigger of customer card form :
IF UserSetup.GET(USERID) THEN BEGIN
MESSAGE(UserSetup."User ID");
IF (UserSetup."Global Dimension 1 Code" <> '') THEN BEGIN
FILTERGROUP := 1;
SETRANGE("Global Dimension 1 Code",UserSetup."Global Dimension 1 Code");
FILTERGROUP := 0;
END;
END;
as global dimension code 1 found in user setup table.it work successfully but after two days when company need to create new customer .i press next from customer card it give me also same number why .
* my no series in financial management is value no je-tc-000001...je-tc-999999
* last customer no added is Je-TC-002700
* incremental rate by 1
* i write this code to stop filter when add new customer but it not work as following
oninsert trigger
cust1.SETRANGE("Global Dimension 1 Code",UserSetup."Global Dimension 1 Code");

cust1.SETRANGE("No.",'Jo-TC-000001','Jo-TC-999999');last number current is Jo-TC-002700

filterlocation:=cust1.GETFILTERS;

IF cust1.FIND('+') THEN

"Global Dimension 1 Code":=filterlocation ;

cust1.INSERT(TRUE);

but now when i add new customer it must come Je-TC-002701.but it not come Je-TC-002701 it come Je-TC-002700 how i will solve this problem.
although it show in table
please help me

thanks

Comments

  • vaprogvaprog Member Posts: 1,141
    without commenting on the rest of your code... add
    cust1."No." := '';
    
    before
    cust1.INSERT(TRUE);
    
  • ahmedbaahmedba Member Posts: 424
    I test it it not prevent or stop filter can any one help me in this if possible
    thanks
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Why do you Always want to insert a new customer when opening a customer card?

    This should be done withing a function, preferably a codeunit that inserts a customer and then opens the card. Not the other way around.
  • ahmedbaahmedba Member Posts: 424
    OK how i make this task now can you help me in this
    i know code unit but how i can do this by code unit
  • vaprogvaprog Member Posts: 1,141
    Please, use punctuation marks in you requests and comments.

    You do not need to clear filters in order to get the next customer number from the number series. In general, though, the code checks whether there is a value in the field before a new number is generated from the series.

    If you do want to clear filters use CLEAR or RESET for the complete record, SETRANGE or SETFILTER for individual fields in one filtergroup, SETTABLEVIEW for all fields in one filtergroup (with the side effect of possibly altering your current key).
    ahmedba wrote:
    filterlocation:=cust1.GETFILTERS;

    IF cust1.FIND('+') THEN

    "Global Dimension 1 Code":=filterlocation ;
    GETFILTERS reads the filters on all fields in the current filtergroup.

    The "Global Dimension 1 Code":=filterlocation ; part of the above code will likely cause a runtime error, or at least set a nonsense filter.

    With the find, all filters are active. You did not clear them anywhere. Furthermore, what's the intention with this. Do you really want to duplicate that customer? Shouldn't you rather use cust1.INIT?

    There is no equivalent in CA/L to a form's PopulateAllFields property nor to the same functionality to primary key fields when the property is not active (in case you are looking for that).

    Why do you need to create a new record programatically anyway? Should't you rather let the user use standard NAV functionality?
  • DenSterDenSter Member Posts: 8,307
    vaprog wrote:
    Please, use punctuation marks in you requests and comments.
    I'd like to see how well you would do in Ahmed's language
  • vaprogvaprog Member Posts: 1,141
    Oh, I am sorry! English is not my native language either, and obviously this sentence of mine sounded to strong, harsh, rude, or wrong in some other way in a native speaker's reading to provoke this response.
    My intention was not at all to put someone down. I just was having trouble to figure out what exactly ahmedba needed help with and thought, some punctuation marks might help. I most likely could cope with some wrongly set marks better than with none at all, but that's maybe just me. My statement was just ment as a kind request (plea? appeal?; not demand!) to help me help you.
  • ahmedbaahmedba Member Posts: 424
    I thanks for all .what i need actually is when i add new customer this customer must show
    but in filter it not show . so that i need to update global dimension code 1 to the filter name i do when i open the form.i want to assign this filter to inserted record. i write in on insert trigger of table the following
    how i do that.
    IF "Global Dimension 1 Code" <> '' THEN

    useri:=UserSetup."Global Dimension 1 Code";

    IF useri = "Global Dimension 1 Code" THEN

    "Global Dimension 1 Code":=useri;
    before insert function
    but it not work why.
    to remember you i put reset in on insert trigger of form it clear filter but he can see another global dimensions also
    I need filter found and i can also insert new record but not see another global dimensions
  • vaprogvaprog Member Posts: 1,141
    Your code does not make much sense to me. I suggest you create a flowchart of it and trace the values it sets and uses on every path through the chart.

    I would do
    IF "Global Dimension 1 Code" = '' THEN BEGIN
      IF UserSetup.GET(USERID) THEN
        VALIDATE("Global Dimension 1 Code",UserSetup."Global Dimension 1 Code");
    END;
    
    Standard NAV uses code like the following in several places (see Sales Header for an example). This disallows filters that are neither single value nor a range. Such filters will cause an error:
    IF GETFILTER("Global Dimension 1 Code") <> '' THEN
      IF GETRANGEMIN("Global Dimension 1 Code") = GETRANGEMAX("Global Dimension 1 Code") THEN
        VALIDATE("Global Dimension 1 Code",GETRANGEMIN("Global Dimension 1 Code"));
    
Sign In or Register to comment.