Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

To find the position of the last 3 letters of Customer No.

Posted on by Microsoft Employee

Hello,


NAV 2009 SP1:There is one scenario where I have to create a new field in Customer table called SAP code.

SAP code will represent combination of Customers’ first 3 letters/digits (without any spaces, dashes, dots, commas
and etc.) and last 3 digits from Customer number.
For example: if Customer’s name is 3-D Air and Customer’s Code is VM0T0000044, then SAP Code will look like this:
3DA044.

And this field has to be updated automatically on validating Customer No. and Name.

This is and urgent requirement so, can anyone tell me how to write the code for this as I am new to NAV?


Thank you in advance :)

 

*This post is locked for comments

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: To find the position of the last 3 letters of Customer No.

    Hello pushpa,

    Just update your code like:

    Customer Table-NO. ONVALIDATE()

    //001

    txtName := DELCHR(Name,'=','-, .');  

    txtName := COPYSTR(txtName, 1 ,3);  

    "SAP Code" := txtName + COPYSTR("No.", (STRLEN("No.")-2) ,STRLEN("No."));

    //001

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: To find the position of the last 3 letters of Customer No.

    I am satisfied with your answer Binesh but when i am writing the code in INSERT trigger in Customer Table I am getting only Customer No last 3 digits automatically Like:

    Customer Table-On INSERT()

    //001

    txtName := DELCHR(Name,'=','-, .');  

    txtName := COPYSTR("SAP Code", 1 ,3);  

    "SAP Code" := txtName + COPYSTR("No.", (STRLEN("No.")-2) ,STRLEN("No."));

    //001

    When I tried to create the new Customer Like

    No. = Hello

    before entering Customer name I am getting the SAP code value=LLO.

    and after entering "No." when I enter the Customer No. = abc123 the SAP code is not updating as ABCLLO.

    SAP Code is coming as LLO only.

    I am writing this code in table level because I have to save the value in Table Field also.

    If i write the code in Form it is possible to see the correct value in form.

    Please suggest me for this.

    Thank you in advance.

  • Suggested answer
    Rabin Profile Picture
    Rabin 2,976 on at
    RE: To find the position of the last 3 letters of Customer No.

    Hi Pushpa,

    If your primary problem is resolved then kindly Verify the answer. If you have additional query then you can create new Thread...

    This will help  others to find the verified links...

    ----------------

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: To find the position of the last 3 letters of Customer No.

    If above suggestion solved your first problem then kindly verify the answer so it will be helpful for others.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: To find the position of the last 3 letters of Customer No.

    Thanks for the suggestion.I will check and let u know people.

    But one more issue i got where i have to first find the doc no from sales line then i have to assign it to the temp table and from temp table i have to check that sales order no is there in Sales header table and if there then i have to display the records, following is my code but the cursor is not going to the line shipped oty condition: please suggest how to solve this as not getting the value in temp table field:

    IF recCustomer.GET(pCustomerNo) THEN

    BEGIN

           lrecSalesLine.RESET;

           lrecSalesLine.SETRANGE("Document Type",lrecSalesLine."Document Type"::Order);

           lrecSalesLine.SETRANGE("Sell-to Customer No.",pCustomerNo);

           lrecSalesLine.SETRANGE("Part/Unit",pItemTypeFilter);

           IF lrecSalesLine.FINDSET THEN

           BEGIN

             //REPEAT

                 IF (lrecSalesLine."Quantity Shipped" < lrecSalesLine.Quantity) THEN        ///Cursor is not coming here

                 BEGIN

                    recSalesTemp."No.":=lrecSalesLine."Document No.";

                    recSalesTemp.INSERT;

                 END;

            // UNTIL lrecSalesLine.NEXT=0;

           END;

    END;

    lrecSalesHeader.RESET;

    //lrecSalesHeader.COPYFILTERS(lrecSalesLine);

    lrecSalesHeader.VALIDATE("No.",recSalesTemp."No.");       //directly cursor comes here after sales line filteration

    IF lrecSalesHeader.FINDSET THEN

       ExpCallOffExistingOrder.SETTABLEVIEW(lrecSalesHeader);

       //MESSAGE('%1',recSalesTemp."No.");

  • Verified answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: To find the position of the last 3 letters of Customer No.

    Hello Pushpa

    Write these code in Form OnAfterGetRecord Trigger.

    Form - OnAfterGetRecord()

    //>>#Sbinesh

    "SAP Code" := DELCHR(Name,'=','-, .');  //Removing special characters from name

    "SAP Code" := COPYSTR("SAP Code", 1 ,3);  // Copy first 3 chars from Name

    "SAP Code" := "SAP Code" + COPYSTR("No.", (STRLEN("No.")-2) ,STRLEN("No.")); // Copy last 3 chars from No.

    //<<#Sbinesh

    Here "SAP Code" is a Table field of Type Code  and Length is 50 in customer Table

    Size is 50 because it assign a  name data, you can also create a variable and assign, but if you don't want to create variable then put size as it Name field size.

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: To find the position of the last 3 letters of Customer No.

    txtString:='VM0T0000044';

    MESSAGE(COPYSTR(txtString,STRLEN(txtString) - 2,3));

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: To find the position of the last 3 letters of Customer No.

    I know with the help of COPY STRING and STRING POS we can do this but how to find the last 3 letters i am not getting as i don't know the exact length of Customer No.

    Like in Example the Customer No. is of 11 characters but it can be of 12 or more.

    So, for this i need code.

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: To find the position of the last 3 letters of Customer No.

    You can use COPYSTR function for the same in Navision

    msdn.microsoft.com/.../dd338944.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans