make a loop in Option value

Hello ,

in Job table i have Field MS Project Type

Field No. Field Name Data Type Length Description
50042 MS Project Type Option

The option value are :
,Admin,Co-Funding,Consulting,Continuous Improvements,Customer PO- Integration,.........ect


how to make a loop instead ?

ListTypeProject:=ListTypeProject + FORMAT(recJobs."MS Project Type"::Admin) ;
ListTypeProject:=ListTypeProject +',' + FORMAT(recJobs."MS Project Type"::"Co-Funding");
ListTypeProject:=ListTypeProject +',' + FORMAT(recJobs."MS Project Type"::Consulting);
ListTypeProject:=ListTypeProject +',' + FORMAT(recJobs."MS Project Type"::"Continuous Improvements");
ListTypeProject:=ListTypeProject +',' + FORMAT(recJobs."MS Project Type"::"Customer PO- Integration");

Thanks
Mounir Haroun



Comments

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    An option is interchangeable with the integer, you can loop on an integer var and assign it to the option field, and then format the value
    FOR i := 1 TO recJobs."MS Project Type"::TheLastOptionValue DO BEGIN
      recJobs."MS Project Type" := i;
      OptValTxt := FORMAT(recJobs."MS Project Type");
      ListTypeProject += ',' + OptValTxt;
    END;
    ListTypeProject := COPYSTR(ListTypeProject, 2);
    

    Note that this is not a foolproof solution, you may need to add some code handling cases when the i var hits in the loop gaps in the option sting (in order to handle cases when the option string is defined like this: ...,SomeOptVal1,,SomeOptVal2... )
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AlexDenAlexDen Member Posts: 86
    You can get OptionString from Field table or FieldRef instead of looping:
    SalesHeader : Record "Sales Header"
    Field : Record Field
    -----------
    Field.GET(DATABASE::"Sales Header", SalesHeader.FIELDNO("Document Type"));
    MESSAGE(Field.OptionString);
    

    In this case you don't have to modify code if new option is added.
  • harounmounirharounmounir Member Posts: 20
    Thanks it work perfect. another question, how i can user this global variable to passed
    third party program using web service

    C# in my odata function i don't find this global variable, but i can find fields of table job.
    suggestion or idea , how to passed options to third party program using web service

    Thanks
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Question still not clear?
    I will request you to verify the current answer and make a new thread for this Question.
  • wolfskinwolfskin Member Posts: 84
    In case of you don't know the last option value.
    IsFinish := FALSE;
    i := 0;
    WHILE NOT IsFinish DO
    BEGIN
     recJobs."MS Project Type" := i;
     IF FORMAT(recJobs."MS Project Type") <> FORMAT(i) THEN
     BEGIN
       IF ListTypeProject = '' THEN
         ListTypeProject := FORMAT(recJobs."MS Project Type")
       ELSE
         ListTypeProject += ',' + FORMAT(recJobs."MS Project Type");
     END ELSE
       IsFinish := TRUE;
     i += 1;
    END;
    

    Thanks
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    wolfskin wrote: »
    In case of you don't know the last option value...
    OptionString=,,I,,Wonder,,How,,This,,,Code,,Will,,,Work,,On,,Such,,Option,,String,,Definition


    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • harounmounirharounmounir Member Posts: 20
    Thanks.
Sign In or Register to comment.