Maximo

Maximo

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

 View Only
Expand all | Collapse all

Maximo Mobile: Make changes to an existing Controller Class

  • 1.  Maximo Mobile: Make changes to an existing Controller Class

    Posted Wed October 25, 2023 07:03 PM

    Hi All,

    Can someone help me understand how to modify an existing function in the Controller.js file.

    I am trying to modify the ComputedRelatedRecordDesc function as I also want to display the relatetype along with the relatedreckey and the relatedrecwodescription. Since I shouldn't be modifying the existing controller file, should this function be called in the appcustomization.js file?

    Thank you in advance!



    ------------------------------
    Chinmaya Kore
    ------------------------------


  • 2.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Thu October 26, 2023 09:52 AM
    computed-function unfortunately only fire the method in the controller and as of 8.11, can't be defined in the AppCustomizations.js. I opened idea https://ibm-ai-apps-internal.ideas.aha.io/ideas/MOBILE1-I-237 for this a while back but customers haven't voted for it so it hasn't really been prioritized.
     
    That being said, you can look at alternative approaches. Up until 8.11 for instance we didn't even use a computed-function to display the data. Our data-list used adaptive-columns and displayed it field by field. You could add another adaptive column to display additional information.

    You could also literally concatenate on to the two attributes using JavaScript. IE modify:

    <label label="{item.computedRelatedRecordDesc}" override-required="true" id="gek7p"/>

    To something like:
    <label label="{item.computedRelatedRecordDesc+' '+item.myotherfield }" override-required="true" id="gek7p"/>
    If you have complex logic that you need to evaluate, you could define a local attribute (<attribute name="myCustomField" local="true"/>) and then populate it on a JavaScript event such as onAfterLoadData(dataSource,items). This event fires for every dataSource so you would want to check the datasource like:
    if(dataSource && dataSource.name==="relatedWorkOrderDs")


    ------------------------------
    Steven Shull
    ------------------------------



  • 3.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Thu October 26, 2023 01:24 PM
    Edited by Chinmaya Kore Thu October 26, 2023 04:14 PM

    Thanks Steven for your reply. It Worked!



    ------------------------------
    Chinmaya Kore
    ------------------------------



  • 4.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Mon October 30, 2023 11:20 PM

    Is there a way to call custom save explicitly on a page. I need to add a new section with a custom field on the report work page ,but there is no OOB save button,we  just have complete work and there is save for each section seperately.

    Thanks,

    Chinmaya Kore.



    ------------------------------
    Chinmaya Kore
    ------------------------------



  • 5.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Tue October 31, 2023 08:16 AM

    Assuming your new field is on the WO record itself (not a separate child object), you can add it to the woDetailsReportWork datasource and display it on the page. Then if you add a button (assuming you have an on-click-arg="{{'item':woDetailsReportWork.item,'datasource':'woDetailsReportWork'}}", in the JavaScript method you declare, you can call the save event on the datasource. Something like below.

    Just be aware that save events like below are not restricted to the field you want to save. If other changes have happened to the datasource that are not yet committed, they will be saved as well. I think on this page you'll be fine since all the dialogs have you save but if that changes in the future, it is something worth being aware of. 

       async detailSave(event)
       {
          let item=event.item;
          let datasource=event.datasource;
          // Any other custom logic here
          await datasource.save();
       }



    ------------------------------
    Steven Shull
    ------------------------------



  • 6.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Tue October 31, 2023 09:27 AM

    Thank you Steven for your response. We need to add the code (async detailSave) in the appcustomization.js file right?



    ------------------------------
    Chinmaya Kore
    ------------------------------



  • 7.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Tue October 31, 2023 09:32 AM

    Yes, we only support customer delivered code in the AppCustomizations.js file today. We don't prevent customers from doing unsupported things (building their own controllers, modifying out of the box controllers, etc.) but you should avoid it as much as possible. Otherwise, it will make even simple patching more difficult. 



    ------------------------------
    Steven Shull
    ------------------------------



  • 8.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Tue October 31, 2023 11:13 AM

    Hi Steven,

    Thank you for the response.

    As suggested , added my attribute in existing datasource woDetailsReportWork

              <attribute name="woeq10" unique-id="true" id="rnsxdv"/>
    post which created a button and added on-clock method and arguments as below
    <smart-input label="WOEQ10" show-verbose="true" value="{woDetailsReportWork.item.woeq10}" />
             <button icon="carbon:checkmark--outline" on-click="detailSave"
             on-click-arg="{{'item':woDetailsReportWork.item,'datasource':'woDetailsReportWork'}}" kind="primary"/>
    and created method in appCustomization.js
    Even post that I am unable to save data I am getting below errors in network
    Thank you for assistance in advance


    ------------------------------
    karishma patil
    ------------------------------



  • 9.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Tue October 31, 2023 11:54 AM

    I'm not understanding how you're seeing the requests that you're seeing here. EventEmitter, Controllable, Button, etc. are core parts of our graphite framework and shouldn't be making network requests to them (they're part of the graphite framework that is bundled in the app). Are you using developer tools on the configuration utility (the thing running on localhost:3001) instead of the preview (the web app running on 3006)? If it failed to build, docker logs or the console output in developer tools is going to be the most useful. That's where we'll log exceptions we encounter generating the react website. If you're seeing issues in the web application, you need to make sure you open developer tools on the window that is running on 3006 to get the JavaScript errors in the console output as that is typically the most useful.

    Are you accessing the docker configuration utility outside of your local system? IE using a URL like http://servername:3001/ instead of http://localhost:3001? I know there were some issues when things weren't running on your local machine that we were making updates to address. 

    I'd probably open a support case so someone from the product team can screenshare and review the logs to understand your specific situation.  



    ------------------------------
    Steven Shull
    ------------------------------



  • 10.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Tue October 31, 2023 02:54 PM

    Hi Steven,

    In regards to SAVE, I tried to use the AUTO-SAVE tag with maximo-datasource but did not workout for me.

    I created a new datasource as below:

    <maximo-datasource controller="" notify-when-parent-loads="false" cache-expiry-ms="1" id="gtassetlabelDS" relationship="gtmassetlabel" depends-on="woDetailResource" selection-mode="none" auto-save="true">
              <schema id="rb8aj">
                <attribute name="iscalibration" id="j97jw"/>
                <attribute name="siteid" id="y96v3"/>
                <attribute name="assetnum" id="aa_6v"/>
              </schema>
            </maximo-datasource>
    >>gtmassetlabel  relationship is defined in workorder table with ASSET Object (assetnum=:assetnum and siteid=:siteid)
    Now I defined below smart input to showcase the field in workorder details page under Asset and Location section.
    <smart-input label="ISCALIBRATION" value="{gtassetlabelDS.item.iscalibration}" id="yzqab"/>
    Above field shows in the preview mode.
     now when I try to change the value in the preview mode for the ISCALIBRATION (YORN) field, it gives an error message as "oslc#update_on_createuri
    Could you please advise what is wrong here?  


    ------------------------------
    Ritesh Ranjan
    Tech Lead (Wipro)
    ------------------------------



  • 11.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Wed November 01, 2023 06:30 PM
    Edited by Chinmaya Kore Wed November 01, 2023 06:30 PM



    ------------------------------
    Chinmaya Kore
    ------------------------------



  • 12.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Fri November 10, 2023 02:13 AM

    An alternative for adding custom computed fields to an existent controller from AppCustomizations.js would be like the one below.

    # On AppCustomizations.js
    
    pageResumed(page, app) {
       this.app = app;
       this.page = page;
    
        // Assuming your computed field is on the Details page
        if (this.page.name === 'workOrderDetails') {
           let woDetailResource = this.page.getMainDatasource();
           let woDetailController = woDetailResource.controllers[0];
           woDetailController['computedCustomField'] = this.computedCustomField;
       }
    }
    
    computedCustomField (item) {
        return `${item.customfield} - ${item.status}`;
    }


    ------------------------------
    Maycon Belfort
    Consultant
    BPD Zenith
    Melbourne
    Australia
    ------------------------------



  • 13.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Mon July 08, 2024 06:07 AM

    Hi Maycon, my requirement is to validate worklog, problem code and remedy before completing the workorder status to COMP. that means while i was about to change the sattus to complete ,it should cross check whetehr tehre is alteast one record either in worklog or failurecode or all the task of the workorder should be completed before chaing the status to comp. Any snippet code to do validations before completing the workorder



    ------------------------------
    UTTAM IBBANDI
    ------------------------------



  • 14.  RE: Maximo Mobile: Make changes to an existing Controller Class

    Posted Mon July 08, 2024 09:19 PM

    Hi Uttam,

    Perhaps this repo can help you with the validations.

    https://github.com/ibm-maximo-mobile-dev/mobile-scripting



    ------------------------------
    If this post helps, please consider accepting it as a solution to help other members find it more quickly.

    Maycon Belfort
    Consultant
    BPD Zenith
    Melbourne
    ------------------------------