Hi,
How do I put this block of code into a function?
Thanks!
IF PurchaseLine.FINDSET THEN REPEAT ReceivedNotInvoiced := ReceivedNotInvoiced + PurchaseLine."A. Rcd. Not Inv. Ex. VAT (LCY)"; UNTIL PurchaseLine.NEXT = 0; AmtRcdNotInv := ReceivedNotInvoiced;
*This post is locked for comments
Hi Patrick,
You may directly go for the method suggested by Shan here and if you need further deep to pass parameters to the function you could create by following his methods here's the way. I'm adding the syntaxed code according to your example here.
When you are defining Locals according to Shan's method you can define Parameters also there. I assume you can pass the main Record or a Purchase Line variable record as a parameter to the function with all the filters and datasets.
You can find it ease as here.
After creating it in that way, your function will be like this.
LOCAL MyFunction(PurchaseLine : Record "Purchase Line") AmtRcdNotInv : Decimal IF PurchaseLine.FINDSET THEN REPEAT ReceivedNotInvoiced := ReceivedNotInvoiced + PurchaseLine."A. Rcd. Not Inv. Ex. VAT (LCY)"; UNTIL PurchaseLine.NEXT = 0; AmtRcdNotInv := ReceivedNotInvoiced;
You can easily see the PurchaseLine record can be accessible inside the function with all the input parameters and filters where you defined in your main code when you called the function.
Hi you can create function. You can create function with return value, or just a function .
But you need to provide where are you going to create this function. This is they way How to create function with return value,
Go to View -> C/AL Globals
Then go to Functions tab
Type the name of the function, Example CalcRcdNotInvoiced , Then click on Locals, then go to Returns Value tab, In the Name field type AmtRcdNotInv , Return type should be Decimal.
Now you have created new function, I guess you do not have any parameters to send, so click F9 and go down then you can see your new function.
Paste your code inside the function now
IF PurchaseLine.FINDSET THEN
REPEAT
ReceivedNotInvoiced := ReceivedNotInvoiced + PurchaseLine."A. Rcd. Not Inv. Ex. VAT (LCY)";
UNTIL PurchaseLine.NEXT = 0;
AmtRcdNotInv := ReceivedNotInvoiced;
If the answer is solved your problem. Please make it as Verified.
Patrick,
What are you trying to achieve, are you expecting your function to return the Amount Received not Invoiced, if so you can add a function with PurchLine as Parameter and add the above code or you could add Document Type and Document No as Parameters for the function and then apply the filters in the function and use the above code.
You need to set the Return Parameter as decimal so that you can retrieve the value.
Hi Patrick,
Can you explain little more here, what exactly you are trying to do?
Where you want to put that code?
Regards,
Sunil
please provide what you tried and what is not working.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,188 Super User 2024 Season 2
Martin Dráb 230,030 Most Valuable Professional
nmaenpaa 101,156