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 Posts: 1,622Member
    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 Posts: 11Member
    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 Posts: 8Member
    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 Posts: 758Member
    Question still not clear?
    I will request you to verify the current answer and make a new thread for this Question.
  • wolfskinwolfskin Posts: 21Member
    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 Posts: 1,622Member
    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
Sign In or Register to comment.