How to read Object Metadata table?

vicky_dada
Member Posts: 106
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?
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?
0
Comments
-
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.0 -
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 lookups0 -
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.com0 -
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?0 -
Got it Guys, =D>
Thanks Rashed for the help0 -
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.0 -
try to recompile the object in nav0
-
I tried this, restarted services but still I face the same thing0
-
delete all the record from object Tracking table and recompile the object and restart the service tier.0
-
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 version0
-
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.0 -
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 ](*,)0 -
did you look at the file it exported? Don't worry about the warning. just run it.
was it a valid xml file??0 -
no files generated, I checked with other records0
-
Click on File->database->alter->Options tab->Enable for Microsoft Dynamics NAV Server and make sure this is checked.0
-
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 blog0 -
oops.
I coppied the code but didn't copy everything.
Thanks for catching that.0 -
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 fine0
-
any clues ](*,) the database alter option is set fine0
-
vicky dada wrote:any clues ](*,) the database alter option is set fineA good programmer makes al the right mistakes
My blog0 -
no,it did not work0
-
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 blog0 -
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?0 -
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 blog0 -
I think No, If I keep the exception then I am not able to read the data.0
-
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.0 -
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 blog0 -
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions