Auto fill fields on form

Prototype1Prototype1 Member Posts: 37
Hi all,
I have a code field on my Contact table(Salesperson Code) I want to write to new Quotations automatically, but I can't get it to work. I have added the field to the Sales Header key and verified it before running the form.
Any suggstions?

Thanks

Tim ](*,)

Answers

  • DenSterDenSter Member Posts: 8,304
    Please explain in more detail what you want to happen.
  • Prototype1Prototype1 Member Posts: 37
    Ok, Details.
    I have the following code run "OnPush" from a "New Quote" Command button on my Sales List Form.

    CASE GETFILTER("Document Type") OF
    'Order' : lrecSH."Document Type" := lrecSH."Document Type"::Order;
    'Quote' : lrecSH."Document Type" := lrecSH."Document Type"::Quote;
    ELSE
    lrecSH."Document Type" := lrecSH."Document Type"::Quote;
    END;

    lrecSH.INSERT(TRUE);
    lrecSH.VALIDATE("Sell-to Contact No.",GETFILTER("Sell-to Contact No."));
    lrecSH.MODIFY(TRUE);

    CASE lrecSH."Document Type" OF
    lrecSH."Document Type"::Order : FORM.RUN(FORM::"Sales Order",lrecSH);
    lrecSH."Document Type"::Quote : FORM.RUN(FORM::"Sales Quote",lrecSH);
    END;
    where lrecSH is the Sales Header Record

    This opens a new Sales Quote Form 41 with the "Sell to address" fields filled in. I want the SalesPerson Code number populated as well.

    Hope this helps

    Tim
  • DenSterDenSter Member Posts: 8,304
    Assuming that the salesperson code comes from the Sell-to Customer, I would personally put that in the Sell-to Customer validation code, in the Sales Header table.
  • Prototype1Prototype1 Member Posts: 37
    Thanks for the repy. I had put the following code as you suggested, but the field doesn't populate.

    Cust.CheckBlockedCustOnDocs(Cust,"Document Type",FALSE,FALSE);
    Cust.TESTFIELD("Gen. Bus. Posting Group");
    "Sell-to Customer Template Code" := '';
    "Sell-to Customer Name" := Cust.Name;
    "Sell-to Customer Name 2" := Cust."Name 2";
    "Sell-to Address" := Cust.Address;
    "Sell-to Address 2" := Cust."Address 2";
    "Sell-to City" := Cust.City;
    "Sell-to Post Code" := Cust."Post Code";
    "Sell-to County" := Cust.County;
    "Sell-to Country/Region Code" := Cust."Country/Region Code";
    "Salesperson Code" := Cust."Salesperson Code"; ///(22.05.09 TFK) M9
    IF NOT SkipSellToContact THEN
    "Sell-to Contact" := Cust.Contact;
    "Gen. Bus. Posting Group" := Cust."Gen. Bus. Posting Group";
    "VAT Bus. Posting Group" := Cust."VAT Bus. Posting Group";
    "Tax Area Code" := Cust."Tax Area Code";
    "Tax Liable" := Cust."Tax Liable";
    "VAT Registration No." := Cust."VAT Registration No.";
    "Shipping Advice" := Cust."Shipping Advice";
    "Type of Supply Code" := Cust."Type of Supply Code";
    "Responsibility Center" := UserMgt.GetRespCenter(0,Cust."Responsibility Center");
    VALIDATE("Location Code",UserMgt.GetLocation(0,Cust."Location Code","Responsibility Center"));

    I have checked the Customer table and the "Salesperson Code" field is on the table and populated. Any further thoughts?
  • DenSterDenSter Member Posts: 8,304
    Have you run the debugger to see if that field gets cleared some other place? Where you put that line of code is where I would start too, but sometimes stuff doesn't happen right when you try it the first time. Your code might populate that field perfectly, but there might be something else going on, which you should investigate by running the debugger. You can't just add some code, and decide that it doesn't work if the results are not what you expect.
  • Prototype1Prototype1 Member Posts: 37
    Point taken.....though debugger didn't throw up any obvious resons that it didn't work. A bit of thought and adding some more code to the "salesperson Code" OnValidate has fixed the problem.
    Thanks for the help.

    Tim
Sign In or Register to comment.