Options

Creating an instance of an option field when using Webservic

marvinqvistmarvinqvist Member Posts: 53
edited 2011-10-28 in NAV Three Tier
Hi,

I am programming a C# application which uses Webservices to perform som Nav logics remotely.

I have a problem when I want to create e.g. new jobs in Nav from the client if the object contains option-fields (e.g. status). The webservice wants an instance of the option-field. But how can I create such an instance??

At the moment I write to a codeunit via webservice, an asks the codeunit to validate an integer into the option-field. It works, but it is an annoying workaround.

Anyone got a hint on how to solve this problem smoothly.!?

Thanks in advance.


/MQ

Comments

  • Options
    ara3nara3n Member Posts: 9,255
    Here is an example.
    MyVendor.Vendor_Service VendWS = new WebServiceApp.MyVendor.Vendor_Service();
    VendWS.UseDefaultCredentials = true;
    MyVendor.Vendor MyVend = new WebServiceApp.MyVendor.Vendor();
    MyVend = VendWS.Read("10000");
    MyVend.Blocked = MyVendor.Blocked.Ship;
    VendWS.Update(ref MyVend);
                
    
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    marvinqvistmarvinqvist Member Posts: 53
    Hi ara3n,

    The syntax is a little different from what I am using. Just to make it clear.. What is MyVendor and WebServiceApp in your code example?

    /MHQ
  • Options
    ara3nara3n Member Posts: 9,255
    MyVendor is the name of web service reference.
    It's the name of the I gave to the web service reference when I selected the Vendor Page from published Nav services.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    marvinqvistmarvinqvist Member Posts: 53
    Aaah...

    Now I get it... I was doing it the right way... I did not know that the options were trigged with the dot.

    e.g. ".Ship". I thought it was something like Blocked(Ship).

    Thanks a lot.!
  • Options
    ara3nara3n Member Posts: 9,255
    You are welcome. :P
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    sbillysbilly Member Posts: 231
    Hi ,
    Please who can tell me how can I fill out a dropdown list in C# with the values of an option field.
    I'm using web services.
    Thanks
  • Options
    yukonyukon Member Posts: 361
    Hi sbilly,

    Try with this method.
    public static void SetEnumSalesLineTypeCombo(DropDownList ctlDropDownList)
            {
                if (ctlDropDownList != null)
                {
                    ArrayList _EnumList = new ArrayList();
                    foreach (string _EnumName in Enum.GetNames(typeof(wsSalesQuoteWeb.Type)))
                        _EnumList.Add(new global_fun.AddEnumValue(global_fun.CultureTextFormats.ToTitleCase(_EnumName.Replace("_", " ")), _EnumName));//Replacing "_" to Blank.
    
                    ctlDropDownList.DataTextField = "Display";
                    ctlDropDownList.DataValueField = "Value";
                    ctlDropDownList.DataSource = _EnumList.ToArray();
                    ctlDropDownList.DataBind();
                }
    			//wsSalesQuoteWeb is your WebService Sales Quote, Sales Order etc,...
            }
    		
    public class CultureTextFormats
        {
            public static string ToTitleCase(String Text)
            {
                System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
                System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
                return textInfo.ToTitleCase(Text.ToLower());
            }
    
            public CultureTextFormats()
            {
                //Do Something
            }
        }
    

    Hope this help.

    Best Regards,
    Yukon
    Make Simple & Easy
  • Options
    philipuskdphilipuskd Member Posts: 36
    hai all,

    i found this thread is very useful. 2 questions though:
    1. do we need to translate the "_" to its relevant caption in the option field ("G_L_Account" => "G/L Account", "_blank_" => " ")? or is there any way to retrieve the actual caption string in the option field?

    2. say user using the combo box and choose a value (e.g.: "G_L_Account"), what value I must use to create / update the records using webservice?

    Regards,

    Philipus
  • Options
    yukonyukon Member Posts: 361
    Hi philipuskd,
    1. do we need to translate the "_" to its relevant caption in the option field ("G_L_Account" => "G/L Account", "_blank_" => " ")? or is there any way to retrieve the actual caption string in the option field?

    Specially, we no need to change it. But i changed the option caption because of i want to show like "NAV" option style.
    We can't directly get caption from WS. Other way you can be use other method.
    2. say user using the combo box and choose a value (e.g.: "G_L_Account"), what value I must use to create / update the records using webservice?

    You can get value from value from your combo follow this way.
    wsSalesLine.Type typItemType = ((wsSalesLine.Type)Enum.Parse(typeof(wsSalesLine.Type), _cboItemType.SelectedValue.ToString()));
    

    Regards,
    Yukon
    Make Simple & Easy
Sign In or Register to comment.