SBX - Search With Button

SBX - Forum Post Title

Pass record in a new page in nav 2017

Microsoft Dynamics NAV Forum

anandb313@gmail.com asked a question on 5 Feb 2018 1:58 AM
My Badges

Question Status

Verified

I have kept a button on the menu items of service order page as "purchase order". Now by clicking the purchase order button purchase order page should open by having the service order no in a lookup field which I have created.

Reply

It's not so clear if you want to create a Purchase Order by passing your field to the header or if you want to "lookup" a purchase order.

If you want to create a purchase order, on the OnAction (click of your button):

1) Create the Purchase Header with your custom field initialized

2) Open the purchase order card by passing the Purchase Header created:

pgPurchaseOrderCard.SETTABLEVIEW(MyPurchaseHeader);

pgPurchaseOrderCard.RUNMODAL;

If you want a lookup:

On the OnAction of your button, you've to:

1) retrieve the purchase order accordingly to your needs (apply correct filters)

2) Pass the purchase order to the Purchase Order Page

You can write something like:

PurchaseHeader.SETRANGE(...); //Here you apply your filters to retrieve the record

pgPurchaseOrderList.SETTABLEVIEW(PurchaseHeader);

pgPurchaseOrderList.LOOKUPMODE(TRUE);

IF pgPurchaseOrderList..RUNMODAL = ACTION::LookupOK THEN

...

Reply
anandb313@gmail.com responded on 5 Feb 2018 2:47 AM
My Badges

Actually on a service order page I customized a button and that button on onlcik should open new purchase order page with the service order number mapped in a customized lookup field. Service order number should get from the current page where the button is kept.

Reply

Ok, so the first part of my previous response.

On your click of the button, create a new Purchase Header with the fields you want populated, then open the Purchase Order Card page as described.

Reply
anandb313@gmail.com responded on 5 Feb 2018 3:10 AM
My Badges

I can able to open a new purchase order by clicking the button through run page link property but i want to know how to populate service order no to my new customized filed in po page

Reply

No, you' don't have to open the page via the RunPageLink. You have to handle it via code because (as previously described):

1) you have to create the Purchase Header filled with your fields

2) After the creation, you have to open the Purchase Order card with the created record in input.

Reply
anandb313@gmail.com responded on 5 Feb 2018 6:25 AM
My Badges

I entered the following code but it doesn't work

PurchaseHeader.RESET;

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

PurchaseHeader.SETRANGE("Service Order No.",PurchaseHeader."Service Order No.");

PurchaseHeader."Service Order No.":=Rec."No.";

PurchaseOrder.SETTABLEVIEW(PurchaseHeader);

PurchaseOrder.RUNMODAL;

here PurchaseHeader is recordset and purchaseorder is page.

Reply
Verified Answer

This code is wrong, line 4 has no sense.

If on the click of your button you want to create a Purchase Header and fill the "Service Order No." field with your Service Order value, you've to do something like this:

 PurchaseHeader.INIT;

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

 PurchaseHeader.INSERT(TRUE);

 PurchaseHeader.VALIDATE("Buy-from Vendor No.",YOURVENDOR);

 PurchaseHeader."Service Order No." := Rec."No.";

 PurchaseHeader.MODIFY(TRUE);

 //Here you've create the Purchase Order

 //Now you open the Purchase Order Card with the created record

 pgPurchaseOrderCard.SETRECORD(PurchaseHeader);

 pgPurchaseOrderCard.RUNMODAL;

Reply
anandb313@gmail.com responded on 5 Feb 2018 11:26 PM
My Badges
Verified Answer

Thank you very much Stefano....

Reply
Muhammad Arif responded on 6 Feb 2018 4:26 AM
My Badges

can you please share the code

Reply
anandb313@gmail.com responded on 8 Feb 2018 5:15 AM
My Badges

As i checked through debugger It executes correctly before the last line of the code

CLEAR(PurchaseHeader);
 PurchaseHeader.INIT;
 PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order;
 PurchaseHeader.INSERT(TRUE);
 PurchaseHeader."Service Order No." := ServHeader."No.";
 PurchaseHeader.MODIFY(TRUE);
 PurchaseOrder.SETRECORD(PurchaseHeader);
 PurchaseOrder.RUNMODAL;


But for the last line  "PurchaseOrder.RUNMODAL;" a error throws that is " The following C/AL functions are limited during write transactions because one or more tables will be locked. Form.RunModal is not allowed in write transactions. codeunit.run is used in write transaction onl if the return vlueis not used.

Reply
anandb313@gmail.com responded on 9 Feb 2018 4:57 AM
My Badges

Now it working after replacing the code for PurchaseOrder.RunModal; as PAGE.RUN(PAGE::"Purchase Order",PurchaseHeader); Thanks

Reply
Anonymous picture
Anonymous
My Badges

Hi Developers,

I'm doing same thing like sending record from custom page to sales Invoice. But on sales invoice ,lookup for customer is not working, as I'm sending 'Customer No.' 

and other question How can I send line items. Please help me out. your help would be appreciated. Thanks.

 My code is 

               var invoiceTable : record "Sales Header";
                           pgInvoiceCard: page "Sales Invoice";
                        
                        begin
                            invoiceTable.INIT;
                            invoiceTable."Document Type" := invoiceTable."Document Type"::Invoice;
                            invoiceTable.INSERT(TRUE);
                            invoiceTable.VALIDATE("Bill-to Customer No.",'10000');
                            invoiceTable."Bill-to Customer No." := '10000';
                         




                            invoiceTable.MODIFY(TRUE);
                            //Here you've create the Purchase Order
                            //Now you open the Purchase Order Card with the created record
                            pgInvoiceCard.LOOKUPMODE(TRUE);
                            pgInvoiceCard.SETRECORD(invoiceTable);
                            pgInvoiceCard.Editable();
                           // pgInvoiceCard.RUNMODAL;
                            PAGE.RUN(PAGE::"Sales Invoice",invoiceTable);
Reply
Anonymous picture
Anonymous
My Badges

I found the solution. Thanks.

Reply
Kunal Panchal responded on 2 Aug 2018 9:34 AM

Is there a way to open a purchase order page in create mode and pass service order no. to it? Then on purchase order page we can get that service order no. and can then fill out the lookup field for service order no.

Reply
Verified Answer

This code is wrong, line 4 has no sense.

If on the click of your button you want to create a Purchase Header and fill the "Service Order No." field with your Service Order value, you've to do something like this:

 PurchaseHeader.INIT;

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

 PurchaseHeader.INSERT(TRUE);

 PurchaseHeader.VALIDATE("Buy-from Vendor No.",YOURVENDOR);

 PurchaseHeader."Service Order No." := Rec."No.";

 PurchaseHeader.MODIFY(TRUE);

 //Here you've create the Purchase Order

 //Now you open the Purchase Order Card with the created record

 pgPurchaseOrderCard.SETRECORD(PurchaseHeader);

 pgPurchaseOrderCard.RUNMODAL;

Reply
anandb313@gmail.com responded on 5 Feb 2018 11:26 PM
My Badges
Verified Answer

Thank you very much Stefano....

Reply

SBX - Two Col Forum

SBX - Migrated JS