Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

X++ in SysDictClass

(0) ShareShare
ReportReport
Posted on by 13

 SysDictClass dictClass =  SysDictClass::newName(classStr(LeaveRequestContract));
DataMemberAttribute attribute = dictClass.getAttribute(classStr(DataMemberAttribute)) ;

Info(strFmt("%1", attribute.Name()));

how to get the label name using datamemberattribute in contact class in x .I have tried the code above mentioned but I am getting the error "Object not set an instance of object".

Any other way or code to achieve this.

Thanks in advance,

Lakshmi.

  • Lakshmi Profile Picture
    Lakshmi 13 on at
    RE: X++ in SysDictClass

    Hi sir, sorry for the late response,

    SysDictMethod dictMethod = new SysDictMethod(UtilElementType::ClassInstanceMethod, classNum(RequestContract), methodStr(RequestContract,parmRequestDate ));
    DataMemberAttribute attribute = dictMethod.getAttribute(classStr(DataMemberAttribute));
    
    Info(strFmt("%1", attribute.Name()));  // works fine return name :- Request date
    
    Now, i need it dynamically 'class name' and 'Method name'
    
    Tmp listOfAttributeName(ClassId _classId, SysMethodName _name)
    {
      // here i want loop all attribute 
      return tmp;
    }
     I want to loop attribute name so that how to do ?

    Thanks 

  • Lakshmi Profile Picture
    Lakshmi 13 on at
    RE: X++ in SysDictClass

    Okay sir, i will bring back parmTransDate lookup and i will go to add another field like.

    Name :-

    ListOfParmsFields

    Description.

    I.e :- if i select to parmTransDate then description will be 'RequestDate' so that we can achieve modified this thing? Or any other alternative way you have please give me.

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: X++ in SysDictClass

    That the value is null means that the variable is empty; it doesn't contain any object. And trying to access properties of nothing (null) is impossible, therefore you get an error. A solution is putting an object to the variable.

  • Lakshmi Profile Picture
    Lakshmi 13 on at
    RE: X++ in SysDictClass

    Sir, i have debugged the same line getting error 'object reference' was it null what does mean already available in the contract class dataMemberAttribute name i didn't get why that error says like.  I'm populate that method in lookup.  

    And it's in-memory table.

    Now, how to overcome object reference error sir.?

    Thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: X++ in SysDictClass

    It seems that attributes is null (you can verify it in debugger), therefore your problem is elsewhere. You need to look at how you populate the value of attributes variable.

  • Lakshmi Profile Picture
    Lakshmi 13 on at
    RE: X++ in SysDictClass

    Thanks sir, i got it.

    I did as you said with AxAttributes

    Now, getting object reference error. (MethodNameTmp.name = attributes.Name getting sir.

    IMG_5F00_20230301_5F00_134403.jpg

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: X++ in SysDictClass

    If you already forgot how to use the enumerator, simply look at your code again and see how the collection of methods is iterated.

    You'll likely get more details in IntelliSense if you declare the variable with a specific type (AxAttribute) instead of var. By the way, it sounds like that you forgot that you can see properties in the debugger.

  • Lakshmi Profile Picture
    Lakshmi 13 on at
    RE: X++ in SysDictClass

    Thanks for your valuable suggestions sir,

    In my contract class i defined dataMemberAttribute for each parm fields and i feel hard only metadata API to be honest I don't know how to iterate the attributes and collection object attributes how to to assign string field? Intellisence if i type some method not come in metadata API that is why i asked give example next time I will keep in mind and will think what I need. Would be great if you provide attributes.

    Thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: X++ in SysDictClass

    Trying to assign a collection of attributes objects to a string field indeed makes no sense at all and it must fail.

    Please stop writing code for a moment and think about what you want.

    Let me help you... A method can be decorated with zero to many attributes. Attributes property contains them, therefore there you can find nothing, a single attribute or multiple attributes there. Before you can get the name, you must find the right attribute: DataMemberAttribute. Therefore you need to iterate the attributes (you should already know how to use an enumerator) and check out their properties to find the right one.

  • Lakshmi Profile Picture
    Lakshmi 13 on at
    RE: X++ in SysDictClass

    Thanks sir, as you said how can I get attribute with axMethod?

    TMP.Name = method.Attributes; getting error sir. If i get attributes then it would be nice and i will get it. That point only I'm stuck.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans