How to read Object Metadata table?

vicky_dadavicky_dada Member Posts: 106
edited 2010-08-05 in NAV Three Tier
Hi Guys,

I am preparing an application using webservices, where I want to know how to identify the lookup fields for eg: No: in sales line is (No = item (where Type = item) or No = GL Acc(where Type = GL Account).....).

I came through one of the post that reading page and table data in object metadata table will give the info. can you guide me on how to use this table?

Comments

  • ara3nara3n Member Posts: 9,256
    write function in NAV and publish it as webservice. The function will pass a BigText as reference. and take two more parameters as Object Type and Object NO.

    Inside the function

    set filter on object type and No. for that table

    calcfields blob field that has the metadata. stream it into the bigText.



    In you C sharp code you have have the BigText string and you can then part and get what you want.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • vicky_dadavicky_dada Member Posts: 106
    Hi Rashed,

    I have created a CU as:

    OBJECT Codeunit 60000 Read MetaData
    {
    OBJECT-PROPERTIES
    {
    Date=05/04/10;
    Time=[ 3:22:34 PM];
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    OnRun=BEGIN
    END;

    }
    CODE
    {

    PROCEDURE ReadObjectMetaData@1000000000(VAR BigtxtVar@1000000000 : BigText;"Object Type"@1000000004 : 'TableData,Table,Form,Report,Dataport,Codeunit,XMLport,MenuSuite,Page,,System,FieldNumber';"Object No"@1000000005 : Integer);
    VAR
    ObjMetaData@1000000003 : Record 2000000071;
    bstr@1000000002 : BigText;
    isstream@1000000001 : InStream;
    BEGIN
    ObjMetaData.RESET;
    ObjMetaData.SETFILTER("Object Type",'%1',"Object Type");
    ObjMetaData.SETRANGE("Object ID","Object No");
    IF ObjMetaData.FINDFIRST THEN BEGIN
    ObjMetaData.CALCFIELDS(Metadata);
    ObjMetaData.Metadata.CREATEINSTREAM(isstream);
    BigtxtVar.READ(isstream);
    END;
    END;

    BEGIN
    END.
    }
    }


    In the C# code I have added as follows
    ObjMeta md = new ObjMeta();
    md.Credentials = new NetworkCredential("Administrator", "123", "WORKGROUP");
    md.Url = ConfigurationManager.AppSettings["ObjMetaData.ObjMeta"];

    String input ,output;
    input = "Blocked";
    output = md.ReadObjectMetaData(ref input,1,18); //- Facing error

    But I am not getting how to part for field, I want to know option values for Blocked field in Customer table and for contiditional lookups
  • wmstreetwmstreet Member Posts: 9
    The option values are defined in the WSDL Schema section. The Schema Type should contain "Restrictions" which are the valid values for an Option Field. Here is some Java code that extracts the values from the schema type passed in the WSDL from Navison 2009 SP1.

    public static List<String> getOptionFieldRestrictionsFromSchema (XmlSchemaSimpleType optionFieldType){
    // the content of the type should contain a collection of restrictions (facets)
    List<String> ret = new ArrayList<String>();
    try {
    XmlSchemaSimpleTypeRestriction typeRestrictions = (XmlSchemaSimpleTypeRestriction)optionFieldType.getContent();
    XmlSchemaObjectCollection facets = typeRestrictions.getFacets();
    int numberOfFields = facets.getCount();
    for (int i = 0; i < numberOfFields; i++) {
    XmlSchemaEnumerationFacet restriction = (XmlSchemaEnumerationFacet)facets.getItem(i);
    ret.add((String)restriction.getValue());
    }
    } catch (Exception e) {
    }
    return ret;
    }
    Wm. Matthew Street (Matt)
    http://www.wmmatthewstreet.com
  • vicky_dadavicky_dada Member Posts: 106
    Thanks street, I got a way of finding the lookups using reflection like CustCard.GetType().GetProperty(FieldVal).GetValue(CustCard, null).gettype.... and added fields to drop down list by looping.

    But I want to know the way to find the coniditions in a lookup field?
  • vicky_dadavicky_dada Member Posts: 106
    Got it Guys, =D>


    Thanks Rashed for the help
  • vicky_dadavicky_dada Member Posts: 106
    Hi Friends,

    Reading the object metadata table is working fine for me but I am not able to read meta data for few tables like T 18, rest everything is working fine, I am running the page and form in RTC its working fine.

    Has anyone experienced this kind of behaviour? I am facing the error "There is an error in XML document (4, -285)." for T-18 in my .net application. this started happening after I restored the backup in a new DB.
  • ara3nara3n Member Posts: 9,256
    try to recompile the object in nav
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • vicky_dadavicky_dada Member Posts: 106
    I tried this, restarted services but still I face the same thing
  • ara3nara3n Member Posts: 9,256
    delete all the record from object Tracking table and recompile the object and restart the service tier.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • vicky_dadavicky_dada Member Posts: 106
    still facing the same thing. Is there any check list kind of thing that I can verify or any info about this table. It is happening in the std version
  • ara3nara3n Member Posts: 9,256
    In NAV write the following code


    ObjectMetadata.setrange("Object type","object type"::Table);
    ObjectMetadata.setrange("Object ID",37);
    ObjectMetadata.CALCFIELDS("Metadata");
    IF ObjectMetadata.Metadata.HASVALUE THEN
      ObjectMetadata.Metadata.EXPORT('c:\ + format(ObjectMetadata"Object ID") + '.xml',FALSE);
    

    after you run this. Open c:\18.xml file make sure it's a valid xml file. If it's not, try to delete the record from Object Metadata an try to recompile the object.
    This will recreate the record.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • vicky_dadavicky_dada Member Posts: 106
    I tried this Rashed but I face warning message "Function 'EXPORT' is obsolete for Microsoft Dynamics NAV Server." however I ried to keep a message box and verified whether it has any value.

    Considering the case of wrong file generated, I am recompiling the object, restarting the server, still the same thing ](*,)
  • ara3nara3n Member Posts: 9,256
    did you look at the file it exported? Don't worry about the warning. just run it.

    was it a valid xml file??
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • vicky_dadavicky_dada Member Posts: 106
    no files generated, I checked with other records
  • ara3nara3n Member Posts: 9,256
    Click on File->database->alter->Options tab->Enable for Microsoft Dynamics NAV Server and make sure this is checked.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kauffmannkauffmann Member Posts: 56
    ara3n wrote:
    In NAV write the following code


    ObjectMetadata.setrange("Object type","object type"::Table);
    ObjectMetadata.setrange("Object ID",37);
    ObjectMetadata.CALCFIELDS("Metadata");
    IF ObjectMetadata.Metadata.HASVALUE THEN
      ObjectMetadata.Metadata.EXPORT('c:\ + format(ObjectMetadata"Object ID") + '.xml',FALSE);
    

    after you run this. Open c:\18.xml file make sure it's a valid xml file. If it's not, try to delete the record from Object Metadata an try to recompile the object.
    This will recreate the record.

    SETRANGE without FIND will not return a record. So the CALCFIELDS results in an empty BLOB...

    Change the code to:
    ObjectMetaData.GET(ObjectMetaData."Object Type"::Table, 37);
    ObjectMetaData.CALCFIELDS(Metadata);
    IF ObjectMetadata.Metadata.HASVALUE THEN
      ObjectMetadata.Metadata.EXPORT(STRSUBSTNO('C:\%1%2_Metadata.xml',FORMAT(ObjectMetaData."Object Type"),ObjectMetaData."Object ID"),FALSE);
    
    A good programmer makes al the right mistakes
    My blog
  • ara3nara3n Member Posts: 9,256
    oops.

    I coppied the code but didn't copy everything.
    Thanks for catching that.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • vicky_dadavicky_dada Member Posts: 106
    oh! I overlooked it. Yes Rashed the field is created but not able to read the same in my application, the issue is for only few tables rest everything is fine and pages metadata is fine
  • vicky_dadavicky_dada Member Posts: 106
    any clues ](*,) the database alter option is set fine
  • kauffmannkauffmann Member Posts: 56
    vicky dada wrote:
    any clues ](*,) the database alter option is set fine
    Remove the record from the Object Metadata table and then open and save your object :?:
    A good programmer makes al the right mistakes
    My blog
  • vicky_dadavicky_dada Member Posts: 106
    no,it did not work
  • kauffmannkauffmann Member Posts: 56
    I assume that the error occurs when transferring the xml file using webservices. Is that corect?

    Are you able to export the Metadata field as an .xml file and open it with Internet Explorer?

    If yes, then you might have a problem with serialization and deserialization of the XML stream via webservices. Are you using Visual Studio? Have you refreshed your webservice reference so that the proxy class is recreated?
    A good programmer makes al the right mistakes
    My blog
  • vicky_dadavicky_dada Member Posts: 106
    Yes Kauffman, the error occurs when transferring the xml file using webservices.

    I found a strange reason for this, actually in by database I have installed Language packs (french, Germany etc) and I have restored the same backup in another Database(same lang packs are installed in this). Here for the Objects for whch I have modified in my DB I was facing the error and rest other was working fine.

    I have again restored the object from CRONUS without other language packs, it is working fine. I did not get why language packs was creating an issue?
  • kauffmannkauffmann Member Posts: 56
    The exception with the message 'There is an error in XML document (<line>, <column>)' typically contains the real exception in the InnerException property.

    Is it possible for you to catch the exception and look into the InnerException property?
    A good programmer makes al the right mistakes
    My blog
  • vicky_dadavicky_dada Member Posts: 106
    I think No, If I keep the exception then I am not able to read the data.
  • ara3nara3n Member Posts: 9,256
    did you export the xml file and take a look at it? Also maybe xml file with caption has certain characters that are not allowed in xml.
    In you .net code save the xml file sent to a file and take a look at it.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kauffmannkauffmann Member Posts: 56
    Since you are having these problems with certain language packs it could be that, for example, special characters in captions or optionvalues cause these problems.

    Try to remove the language from just one object and see if that solves the problem.
    A good programmer makes al the right mistakes
    My blog
  • brucembrucem Member Posts: 86
    Hi,

    i have seen this sort of error with the customer table when trying to export fields with captions attached

    for example field 10015 Tax Exemption No.

    The caption ML is as below, the parse does not like the FRC sections.

    ENU=Tax Exemption No.;FRC=N° d'exonération fiscale;ENC=Tax Exemption No.
Sign In or Register to comment.