Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  SRMOBILE Location lookup

    Posted 24 days ago

    Dears,

    I hope you all are doing very well.

    I'm currently working on a case on the SRMOBILE  where we have two types of locations: ATMs and Branches, and three main classifications: OM, SOFT, and ATM.

    The requirement is as follows:

    • When a user selects OM or SOFT as the main classification, the location lookup should display Branch locations only.

    • When the user selects ATM as the main classification, the lookup should display ATM locations only.

    I've been trying to implement this logic but have been stuck for a while. If anyone has suggestions or can point me in the right direction, it would be greatly appreciated.

    NOTE: I know that in most of the cases the drilldown won't work but this is not a big issue for me, the most important that the search functionality separates the locations

    Thank you in advance for your support!



    ------------------------------
    Mostafa Mosaad
    Software Engineer
    Megasoft
    Cairo
    01117275779
    ------------------------------


  • 2.  RE: SRMOBILE Location lookup

    Posted 24 days ago

    Hi @Mostafa Mosaad

    In my opinion you should be able to achieve that by customising this method CreateSRController:drillInLocation(item).

    Information about the current selected category you can find in this state variable: this.app.state.topcategorydesc

     



    ------------------------------
    Bartosz Marchewka
    IBM Maximo Consultant
    AFRY
    ------------------------------



  • 3.  RE: SRMOBILE Location lookup

    Posted 23 days ago

    Hi Bartosz,

    Thanks a lot for the information - much appreciated.

    Unfortunately, due to the client's environment policies, I won't have access to the container to pull the backend code any time soon. I'm currently restricted to working within the online AppFramework, which only provides access to app.xml and appcustomization.js.

    I was thinking along the lines of using a ternary clause within the mxapioperlocation to check against the state you mentioned, but I haven't been able to get it to work just yet.

    Thanks again, and I'll keep you posted if I manage to find a workaround.

    Best regards,



    ------------------------------
    Mostafa Mosaad
    Software Engineer
    Megasoft
    Cairo
    01117275779
    ------------------------------



  • 4.  RE: SRMOBILE Location lookup

    Posted 23 days ago

    if there are no workaround but adjusting the above function would it be something like this if am assuming correctly

    async drillInLocation(item) {
      let ds = this.page.datasources["locationHierarchyDS"];
      ds.initializeQbe();
      if (ds.lastQuery) {
        ds.lastQuery.searchText = "";
      }
     
      let category = this.app.state.topcategorydesc;
     
      if (this.app.state.isMobileContainer) {
        if (item) {
          ds.setQBE("parent", "=", item.location);
          ds.setQBE("primarysystem", true);
          ds.setQBE("systemid", "=", item.systemid);
        } else {
          ds.setQBE("parent", "!=", "*");
          ds.setQBE("primarysystem", true);
        }
      } else {
        if (item) {
          ds.setQBE("LOCHIERLOCONLY.parent", "=", item.location);
        } else {
          ds.setQBE("LOCHIERLOCONLY.parent", "=", "null");
        }
        ds.setQBE("LOCHIERLOCONLY.LOCSYSTEM.primarysystem", "=true");
      }
     
      if (category === "OM" || category === "SOFT") {
        ds.setQBE("LOCHIERLOCONLY.type", "=", "Branch");
      } else if (category === "ATM") {
        ds.setQBE("LOCHIERLOCONLY.type", "=", "ATM");
      }
     
      await ds.searchQBE();
    }


    ------------------------------
    Mostafa Mosaad
    Software Engineer
    Megasoft
    Cairo
    01117275779
    ------------------------------



  • 5.  RE: SRMOBILE Location lookup
    Best Answer

    Posted 23 days ago

    Hi @Mostafa Mosaad

    If you can't customise java script mentioned above then I think you could add asynconBeforeLoadData(datasource, query) method into AppCustomizations.js

    Please don't treat the code below as final one, but as an idea how to do that:

     class AppCustomizations {
       applicationInitialized(page, app) {
         this.app = app;
         this.page = page;
       }
     async onBeforeLoadData(datasource, query) {
         if(datasource.name === 'locationHierarchyDS') {
           let category = this.page.state.topcategorydesc;
           if(category === "OM" || category === "SOFT") {
             if (this.page.state.isMobileContainer && !datasource.lastQuery.qbe['type']){
               datasource.setQBE("type", "=", "Branch");
               await datasource.searchQBE();
               datasource.forceReload();
             } else if(!this.page.state.isMobileContainer  && !datasource.lastQuery.qbe['LOCHIERLOCONLY.type']) {
               datasource.setQBE("LOCHIERLOCONLY.type", "=", "Branch");
               await datasource.searchQBE();
               datasource.forceReload();
             }
            //FIXME:  For ATM
           }
         }
       }
    }


    ------------------------------
    Bartosz Marchewka
    IBM Maximo Consultant
    AFRY
    ------------------------------



  • 6.  RE: SRMOBILE Location lookup

    Posted 22 days ago
    Edited by Mostafa Mosaad 22 days ago

    Hi Bartosz,

    Thank you so much for your initial code - it really helped me get started and led me toward achieving the desired functionality. I used your code as a solid foundation and built upon it until I reached this working version:

    javascript
    class AppCustomizations { applicationInitialized(page, app) { this.app = app; this.page = page; this.lastCategory = null; } async onBeforeLoadData(datasource) { if (datasource.name !== 'locationHierarchyDS') return; const category = this.page.state.topcategorydesc; let typeValue; switch (category) { case "General Services": case "Operational Services": typeValue = "VENDOR"; break; case "ATM Services": typeValue = "SALVAGE"; break; } if (!typeValue || this.lastCategory === category) return; datasource.clearQBE(); datasource.setQBE("type", "=", typeValue); this.lastCategory = category; await datasource.searchQBE(); await datasource.forceReload(); } } export default AppCustomizations;

    I faced a couple of issues along the way - like the oslc.where from the backend interfering with my QBE filters, which initially returned empty results. I realized I had to call clearQBE() first to avoid conflicting filters.

    Another issue was the filter persisting even after I changed categories. Adding a lastCategory check helped avoid unnecessary reloads when the same category is selected again.


    I'd really appreciate your feedback as someone more experienced with this.

    Also, I have been trying to filter by a custom attribute on the location object, i made sure it is not excluded in the mxapioperloc object structure, also i added it as an attribute in the locationLookupDS Data source with no luck, do you have any idea why is this happening ?

    Thanks again for your help - your starting point made a huge difference!



    ------------------------------
    Mostafa Mosaad
    Software Engineer
    Megasoft
    Cairo
    01117275779
    ------------------------------



  • 7.  RE: SRMOBILE Location lookup

    Posted 22 days ago
    Edited by Bartosz Marchewka 22 days ago

    Hi @Mostafa Mosaad

    I'm glad that I could help you to move forward with this customisation. If may I suggest, please:

    • review if your solution is properly working in real Mobile Device as well in Role Based Applications (RBA). For some reasons IBM is building QBE in a different way when the flag this.page.state.isMobileContainer is set to False
    • consider to move your variable lastCategory to the app state section (add it to app.xml maximo-application -> states -> state) and manipulate it in the same way how IBM is doing for other states (for example topcategorydesc).

    If it comes to your question about locationLookupDS don't know why it's not working. Maybe you can try to set property searchable="true" for your custom attribute and check if this helped.



    ------------------------------
    Bartosz Marchewka
    IBM Maximo Consultant
    AFRY
    ------------------------------



  • 8.  RE: SRMOBILE Location lookup

    Posted 22 days ago

    Hi @Bartosz Marchewka,

    Thank you so much for your feedback and thoughtful suggestions!

    I'm glad I was able to move forward with this customization thanks to your insights. To address your point - the searchable="true" flag is already set on the custom attribute bgtype, but unfortunately it's still not returning results when applying the QBE filter.

    That said, I'll take your advice and dive deeper into debugging, particularly:

    • Testing on a real mobile device to check behavior under different environments, especially when isMobileContainer is false.

    • Refactoring the lastCategory logic into the app state, as you suggested, to keep consistency with how IBM manages state like topcategorydesc.

    Appreciate the time and direction - I'll keep digging!



    ------------------------------
    Mostafa Mosaad
    Software Engineer
    Megasoft
    Cairo
    01117275779
    ------------------------------