Loop of function not desired

Alva1Alva1 Member Posts: 24
Hi,

I open a STRMENU window through a function in a codeunit which set the users choice and save it in a Variable.(integer form 1 to 4)
This codeunit calls the Contact rec.
It works fine but it runs in a loop stage(finds a contact and ask through the menu to set a choice over and over again).
What i wanted to do is to set this choice just once and keep that chosen integer(for example 1)for all the contacts, and then through IF THEN statements run different operations:
IF Variable = 1 THEN
DO THIS;
IF variable = 2 THEN
DO THIS

Is there a possibility to achieve this???
Best regards

Alva1

Answers

  • SogSog Member Posts: 1,023
    ModifyAll(Field, newvalue,[runtrigger]) modifies the value for the specified field for all the records in a specified Range/Filter.
    For the not looping, you could write your own function, instead of calling the codeunit
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Alva1Alva1 Member Posts: 24
    Hi Sog,

    Thank you for your quick response!
    My first initial thought was to run the STRMENU through a form, so the variable would be set only once.
    What i don't really know how to do is to give the value of the variable to the codeunit(so the codeunit take the variable and runs the function using the given value!)

    any tips or ideas??
    Best regards

    Alva1
  • markborgesmarkborges Member Posts: 170
    Hi Alva1,

    Can you put a part of the code you're trying to do here?

    It's hard to understand what you really want/need... :-k

    :wink:
    Marcelo Borges
    D365 Business Central Solutions Architect
    BC AL/NAV C/AL Developer
    BC Repositories.com
  • SogSog Member Posts: 1,023
    If you design the codeunit with the function, go to the c/al globals, tab functions.
    Select the function you want to use and click on 'locals'.
    There you see in the first tab (parameters) which parameters the function requires.
    If there aren't any parameters, you can't pass along parameters unless you edit that function. (not recommended)

    If you just run the codeunit, the 'run' function does not have any parameters thus you can't pass along parameters.
    to pass along parameters use something like this

    var_cu (global or local variable of the type codeunit and subtype the codeunit you want to use)
    var_int (your integer which represents the option?)

    var_cu.function(var_int); //<- this line calls the codeunit's function with the integer as parameter
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • kinekine Member Posts: 12,562
    It means that you have wrong design of the process. The value selection must be made before the loop. It seems you have it as part of the loop... but without the code.... :wink:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,305
    Alva1 wrote:
    Is there a possibility to achieve this???
    Yes, display the menu before the loop starts.
  • Alva1Alva1 Member Posts: 24
    Hi Thank you for all the answers!

    but i think i didn't explain it very well so ill do it better this time:

    is about the Outlook Synchronisation.
    When the user opens the Salesperson Purchaser card, there is this outlook Synch tab, what i wanted to do is when people press this button to synch(or sometime between the whole process) a MESSAGE pops out and ask the user how does he want to save the contacts in Outlook, automatically after that the STRMENU pops out showing 4 options
    1)option 1
    2)Option 2
    3)Option 3
    4)Option 4
    If the user press cancel, the form will automatically close.
    I managed to do this, but now comes the tricky part:
    The Codeunit 5069 Outlook Contact Handler is the one incharge of creating contacts in Outlook, and there is this function ASSIGN which is incharge of assign the different navision fields to Outlook.
    For example:

    OlContactFileAs := Cont.Name

    here is where i write some IF THEN statements to set how the contacts should be saved in Outlook
    For example:

    IF OptionChoosenFromUser = 1 THEN
    OlContactFileAs := Cont."Company Name"+' '+Cont.Name;
    IF OptionChoosenFromUser = 2 THEN
    OlContactFileAs := Cont.Name
    and so on.

    what i wanted is to save somehow the Option choosen from the user and use it for every loop in this function ASSIGN.
    but i don't really know how to do this and which is the best way!
    Best regards

    Alva1
  • kinekine Member Posts: 12,562
    It means, that the user will select the option only once, and after that, the process will go automatically with this setting each time? If yes, you need to store the value into some table (e.g. user setup) and read it from there.

    And one tip: try to use CASE statement instead

    if something = x then
    if something = y then
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Alva1Alva1 Member Posts: 24
    Thank you guys for helping me out everything worked perfectly out!
    Best regards

    Alva1
Sign In or Register to comment.