13 Replies Latest reply on Mar 21, 2019 11:13 AM by Lonnie Murray

    Retrieve menu Items from C API?

    Lonnie Murray
      Share:|

      I'm new to the C API and I'm struggling to figure out how to get the ARGetCharMenu and  ARExpandCharMenu function.   I keep getting "Access violation writing location".

       

      I feel like maybe I'm sending the data to the function in the wrong way, or declaring my variables incorrectly? 

       

      I'm new to programming in C++ so the obscurity of the error messages is kind of frustrating.  Here's what I'm passing in...

       

      ARCharMenuStruct menuDef;

      char *nameR = "SC:Cabling";

      ARGetCharMenu(&c, nameR, 0, menuDef, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

       

      Is there a code example of retrieving a simple character menu list out there? 

        • 1. Re: Retrieve menu Items from C API?
          Misi Mladoniczky

          Hi,

           

          This depends on the menuType.

           

          If it is a simple AR_CHAR_MENU_LIST the items would be included in the definition.

           

          For the others you might use ARExpandCharMenu as a second call, I think, to search for the data and return a new ARCharMenuStruct which is always of the type AR_CHAR_MENU_LIST.

           

          Then you traverse the tree in menuExpandedDef.u.menuList...

           

          How to traverse this should be deducible from reading the ar.h file. This file is the one I read manually the most when doing the AR C API.

           

          The other one is to read the API documentation for the function you want to use. It is pretty good. ARExpandCharMenu - Documentation for Remedy Action Request System 18.05 - BMC Documentation

           

                  Best Regards - Misi, RRR AB, http://rrr.se

          1 of 1 people found this helpful
          • 2. Re: Retrieve menu Items from C API?
            Lonnie Murray

            I did read the documentation.  When I debug the function though I'm getting memory errors.  I think I must be missing something basic about the way the variables are declared or referenced.    A basic C++ example, of enumerating a simple AR_CHAR_MENU_LIST would be super helpful if anyone has one.    In my example above, is there anything I'm doing wrong?    If I debug the function, I can hover over the variable and see that menuDef is encountering some kind of memory issue.    Do I need to allocate memory to the object that will later hold the menu?

            As I said above, I'm kind of new to C++, but I do know quite a few other languages.   (I also took a class in C many years ago...)   This all seems a little cryptic to me since I'm not getting common-sense error messages.    

            • 3. Re: Retrieve menu Items from C API?
              Lonnie Murray

              I should also mention that I've used the .net quite extensively.   I just wanted to rewrite one of my functions in C, since the .Net library was never really supported.    (Yes, I've also considered rewriting in JAVA since BMC is heading that way, but I'm not ready to go that direction yet.)   Besides...  It frustrates me that I don't know how to do this.  Even if I don't take this option, I still kind of want to know how to do it. 

              • 4. Re: Retrieve menu Items from C API?
                Misi Mladoniczky

                Hi,

                 

                It needs a pointer to the ARCharMenuStruct, but you are passing the object itself. Try passing &menuDef instead.

                 

                Make sure to include arextern.h in your project, and you should get type errors when you compile.

                 

                        Best Regards - Misi, RRR AB, http://rrr.se

                1 of 1 people found this helpful
                • 5. Re: Retrieve menu Items from C API?
                  Lonnie Murray

                  Yes, that's what I was missing.  Thanks.

                  • 6. Re: Retrieve menu Items from C API?
                    Lonnie Murray

                    Okay, similar problem to the one above... what am I doing wrong?  I can't get it to return anything.

                     

                    ARInternalId rmFieldID = 7; /* Remedy Field ID */

                    ARNameType rmFieldName;

                    ARFieldMappingStruct *rmfieldMap;

                    unsigned int *rmDataType;

                    unsigned int *rmOption;

                    unsigned int *rmCreateMode;

                    unsigned int *rmFieldOption;

                    ARValueStruct *rmDefaultVal;

                    ARFieldLimitStruct *rmLimit;

                    ARPropList *rmObjPropList;

                    ARNameType *rmFormThing = "AM:MainAsset";

                     

                    ARGetField(&c, rmFormThing, rmFieldID, rmFieldName, &rmfieldMap, &rmDataType, &rmOption, &rmCreateMode, &rmFieldOption, &rmDefaultVal, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &rmObjPropList, &s);

                     

                    My suspicion is that I'm doing something wrong with the field ID. 

                    • 7. Re: Retrieve menu Items from C API?
                      Lonnie Murray

                      Actually, never mind.  I figured out what I did wrong...

                      • 8. Re: Retrieve menu Items from C API?
                        Misi Mladoniczky

                        Just for the record then. You defined pointers (unsigned int *) instead of object (unsigned int) by using the * in front of them.

                        These values was also not initialized.

                        And then you passed a pointer to the pointer (unsigned int **)  instead of the actual pointer to the object (unsigned int) to ARGetField.

                        /Misi

                        • 9. Re: Retrieve menu Items from C API?
                          Lonnie Murray

                          Yes, more or less (partially a copy paste error).  Thanks for your patience!   Anyway, I got ARGetCharMenu to work fine, at least for list fields.  I'm still struggling though a bit with ARExpandCharMenu for Query fields.   

                           

                          I get the menu definition from ARGetCharMenu, but I can't seem to extract the menu from rmMenuOut

                           

                          ARCharMenuStruct rmMenuOut; /* The menu to be returned */

                          ARCharMenuStruct menuDef; /*Menu definition populated from ARGetCharMenu */

                          ARCharMenuList  myMenu;

                           

                               ARExpandCharMenu(&c, &menuDef,0, 0, &rmMenuOut, &s);

                               myMenu = rmMenuOut.u.menuList;

                           

                               }

                               for (i = 0; i < myMenu.numItems; ++i) {

                                    char tmpVal[80];

                                    strcat(JSONOut, "{");

                                    strcpy(tmpVal, myMenu.charMenuList[i].menuLabel);  // charMenuList shows items but it cant retrieve the values.

                                    strcat(JSONOut, "Value:");

                                    strcat(JSONOut, "\'");

                                    strcat(JSONOut, tmpVal);

                                    strcat(JSONOut, "\'");

                                    strcat(JSONOut, "}");

                                    if (i + 1 < myMenu.numItems) {

                                         strcat(JSONOut, ",");

                                    }

                               }

                          • 10. Re: Retrieve menu Items from C API?
                            Lonnie Murray

                            Nevermind, I figured this one out too...  There seems to be a difference between the documentation and the function itself.  This time I don't think it's me...   If I call this instead, it works:

                             

                            ARExpandCharMenu(&c, &menuDef,0, &rmMenuOut, 0, &s);


                            When I look at the function definition, it makes sense, but it doesn't match the documentation:

                             

                             

                            EXTERN_FUNCTION (int ARExpandCharMenu, (ARControlStruct *, ARCharMenuStruct *,

                                                   unsigned int maxRetrieve, ARCharMenuStruct *, unsigned int *numMatches, ARStatusList *));

                            • 11. Re: Retrieve menu Items from C API?
                              Misi Mladoniczky

                              Hi,

                               

                              Yes, you are right. I submitted a comment about it to the documentation people.

                               

                              But you should make use of arextern.h to give you errors automatically!

                               

                              I created this funny little utility to check how things change between versions, and apparently the parameters to ARExpandCharMenu was changed between version 7.6.03 and 7.6.04. Slide the sliders to check out how the system evolves: ARAPI Version Comparison

                               

                              Best Regards - Misi, RRR AB, http://rrr.se

                              1 of 1 people found this helpful
                              • 12. Re: Retrieve menu Items from C API?
                                Lonnie Murray

                                I do include arextern.h but it doesn't seem to provide me useful errors. Maybe Because I'm using Visual Studio 2017?  I don't know...

                                Anyway... One last question then I'm DONE.   How do you pass field values to the menu definition object for query menus with queries like ('Asset Category' = $200000003$)?   Clearly Appaji figured this out when he created the .net API but I can't find instructions in the C API documentation itself.

                                 

                                Also, I'd love to make my tool to get Remedy menus public (for both criticism and acclaim).  Is there a BMC public GIT repository I can post it to?    (Okay, fine I suppose that's a *second* question....) .  I also have a way to integrate it with Node.js if anyone is interested... 

                                • 13. Re: Retrieve menu Items from C API?
                                  Lonnie Murray

                                  Also, I love your tool.  Nifty.