web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Set the value of a dropdown option

(0) ShareShare
ReportReport
Posted on by 575

Hi guys

I've attempting to create a Purchase Order from a Sales Order (got this working thanx to Franz) but I'm curious how I go about setting the value of a dropdown on the Purchase Order based on the value from a similar field in Sales Order?

I know I could use something like:

purchHeader."Ship-to Code" := SalesOrderID."Ship-to Code"

However, these fields don't marry up properly. What I'm looking to do is something like:

if purchHeader."Ship-to Code" = "whatever" then

SalesOrderID."Ship-to Code" = "something else"

else if purchHeader."Ship-to Code" := ...

Hopefully you get the idea. The problem I have is knowing how to set the value of the dropdown field on the Purchase Order from the Sales Order.

Can anyone point me to where that can be done

Thanx

Steven

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    hi,

    the values belong to different option lists, so cannot match directly.

    you could use case-of statement like

    Source := 'abc';

    var Target...;  

    case Source of  

     'abc':  

       Target := '123';  

     'def':  

       Target := '456';  

    else  

     Target := '000';

    end;

  • Steven O'Neill Profile Picture
    575 on at

    Thanx Franz

    I can see this working if I create the Option field in my var (I've added an Option field like so: ShippingAdd: Option "Default (Sell-to Address)","Alternate Shipping Address","Custom Address";) but I'm having an issue referencing the actual field from the Sales Order that I need.

    What I really need to be able to reference the Ship-To field in the Sales Order and I don't seem to be able to do this as a var so obviously I'm doing something wrong here.

    In my var I have: SalesOrderID: Record "Sales Header"; and within my begin statement I can reference fields within the SalesOrderID but not from within the var creation point.

    Any idea what I'm missing here?

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    i rechecked the whole thing.

    it should work simply.

    both are code fields, target to the same tablerelation.

    so purchHeader."ship-to code" := salesHeader."ship-to code" should work. 

    but ... the field "sell-to customer no." in purchHeader should be set first, with the same property value from salesHeader,

    because ship-to code references that field in it's tablerelation (that is needed for the dropdown). 

    additional, you should use purchHeader.validate("ship-to code", salesHeader."ship-to code") instead of the direct assignment,

    because only then the onvalidate trigger of field ship-to code is run. the other ship-to fields are then set properly.

    you can check that e.g. on http://motochini.com/v11.00/object/tab/36
    or you use the old developer environment.
    you should also add extension "al object designer" to vs-code env. that helps to check the code in the standard objects.

    also checkout cu 1314 "PurchInvFromSalesInvoice".
    you could use that code as template for your intention. 

  • Steven O'Neill Profile Picture
    575 on at

    Hi Franz

    Thanx once again for getting back to me here. Think I must just be not following this as it's still not working I'm afraid. Here is what my Action looks like atm:

               action(CreatePO)

               {

                   Caption = 'Create Purchase Order';

                   ToolTip = 'Create new Purchase Order and add Item Lines from Sales Quote';

                   ApplicationArea = All;

                   Image = Add;

                   Promoted = true;

                   PromotedCategory = Process;

                   PromotedIsBig = true;

                   trigger OnAction()

                   var

                       SalesOrderID: Record "Sales Header";

                       purchHeader: Record "Purchase Header";

                   begin

                       purchHeader."Document Type" := purchHeader."Document Type"::Order;

                       purchHeader."Document Date" := SalesOrderID."Document Date";

                       purchHeader."Due Date" := SalesOrderID."Due Date";

                       purchHeader."Ship-to Code" := SalesOrderID."Ship-to Code";

                       purchHeader."Sell-to Customer No." := SalesOrderID."Sell-to Customer No.";

                       case SalesOrderID."Ship-to Code" of

                           '0':

                               purchHeader.Validate("Ship-to Code", SalesOrderID."Ship-to Code");

                           '1':

                               purchHeader.Validate("Ship-to Code", SalesOrderID."Ship-to Code");

                           '2':

                               purchHeader.Validate("Ship-to Code", SalesOrderID."Ship-to Code");

                       end;

                       purchHeader.Insert(true);

                       page.run(page::"Purchase Order", purchHeader);

                   end;

               }

    Is there something obvious that appears to be missing from this?

    Thanx

    Steven

  • Verified answer
    keoma Profile Picture
    32,729 on at

    it's needed to know the standard business processes very exactly.

    following the code, that works:

    pageextension 50102 SalesQuoteListExt extends "Sales Quotes"

    {

       actions

       {

           addlast(Processing)

           {

               action(CreatePO)

               {

                   Caption = 'Create Purchase Order';

                   ToolTip = 'Create new Purchase Order and add Item Lines from Sales Quote';

                   ApplicationArea = All;

                   Image = Add;

                   Promoted = true;

                   PromotedCategory = Process;

                   PromotedIsBig = true;

                   trigger OnAction()

                   var

                       salesHeader: Record "Sales Header";

                       purchHeader: Record "Purchase Header";

                   begin

                       //select first sales quote of list: change that as you need

                       salesHeader.SetRange("Document Type", salesHeader."Document Type"::Quote);

                       salesHeader.FindFirst();

                       // sales quote loaded?

                       if salesHeader."No." = '' then

                           exit;

                       clear(purchHeader);

                       purchHeader."Document Type" := purchHeader."Document Type"::Order;

                       purchHeader.Validate("Buy-from Vendor No.", '10000'); // default vendor

                       purchHeader."Vendor Invoice No." := 'DUMMY-01';

                       // sets (doc.) no. autom., but also fields "sell-to customer no." and "ship-to code" to ''

                       // means, if these values are set before insert, then they are overwritten

                       // seems to be default behavior

                       // so first make insert, then set the values, then  make a modify to get the correct values

                       purchHeader.Insert(true);

                       purchHeader."Document Date" := SalesHeader."Document Date"; // or use workdate as default

                       purchHeader."Due Date" := Salesheader."Due Date";

                       purchHeader."Sell-to Customer No." := Salesheader."Sell-to Customer No.";

                       if Salesheader."Ship-to Code" <> '' then

                           purchHeader.Validate("Ship-to Code", Salesheader."Ship-to Code")

                       else begin

                           //ship-to code can be empty, but the adress fields can have a value

                           purchHeader."Ship-to Name" := salesHeader."Ship-to Name";

                           purchHeader."Ship-to Address" := salesHeader."Ship-to Address";

                           purchHeader."Ship-to Address 2" := salesHeader."Ship-to Address 2";

                           purchHeader."Ship-to Post Code" := salesHeader."Ship-to Post Code";

                           purchHeader."Ship-to City" := salesHeader."Ship-to City";

                           purchHeader."Ship-to Contact" := salesHeader."Ship-to Contact";

                           purchHeader."Ship-to Country/Region Code" := salesHeader."Ship-to Country/Region Code";

                       end;

                       purchHeader.Modify();

                       page.run(page::"Purchase Order", purchHeader);

                   end;

               }

           }

       }

    }

  • Steven O'Neill Profile Picture
    575 on at

    Thanx Franz. This is a massive help and I think I'm beginning to see how I need to work with this...no doubt be back again though lol

  • keoma Profile Picture
    32,729 on at

    additional you should save the sales quote no. in the purchase order and vice versa to not loose the connection between them.

  • Steven O'Neill Profile Picture
    575 on at

    Hi Franz

    Yeah I'm thinking here that I'll probably need a 1:N relationship for the Purchase Order back to the Sales Order (as there may be multiple PO's needed for each Sales Order). However, we'll only have the one Sales Order for the Purchase Order so I can add a field in the PO for the Sales Order.

    Since we're using Drop Shipments for everything, we may well just be able to use the Drop Shipment action from the Purchase Order and this updates the Sales Lines back on the Sales Order so we don't need to tie these back as such but would still be useful to be able to open the Purchase Orders directly from the Sales Order and I'm assuming I'll need to create List to be able to do this but that part of the next process here :)

    Steven

  • keoma Profile Picture
    32,729 on at

    you create the PO on base of sales quotes. in the sales quote there is no drop shipment function and the drop shipment function in the PO page targets a sales order.

    that would only work, if you work with sales orders instead.

  • Steven O'Neill Profile Picture
    575 on at

    Hi Franz

    Yeah I realise what we original spoke about was creating the Purchase Quote from a Sales Quote but when I began looking at using Drop Shipments at the Quote points I soon realised it wasn't going to work (which I still find strange as there are businesses out there that don't have stock/inventory but always have drop shipments). So I've went back to the original discussion and everything is being done via Sales/Purchase Orders and I'll add a field into both that states if we're at a Quote or Order point so that it keeps things right. I'll then drop everything about Quotes from the system and concentrate on Orders/Invoices only going forward.

    I've already adapted the code to accommodate this.

    Steven

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,785

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,007 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 948 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans