Maximo

Maximo

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

 View Only
Expand all | Collapse all

Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

  • 1.  Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Wed November 22, 2023 11:48 AM

    I am trying to add iscalibration field from asset table in Asset and location section in workorder detail page and adding custom save on that but it is not working.

    Please help.

    Below are the steps I have taken.

    1. Added iscalibration attribute in wodetailResource datasource as below inside asset attribute section which was already there.

    <attribute name="asset" id="anxax">
                <attribute name="description--assetdesc" id="p2r49"/>
                <attribute name="assetnum--assetnumber" id="jvmw9"/>
                <attribute name="assettype--assettype" id="v6yaw"/>
                <attribute name="manufacturer--company" id="rvwvm"/>
                <attribute name="isrunning--assetisrunning" id="r3xq5"/>
                <attribute name="iscalibration--gtassetlabel" id="pgz2b"/>
    </attribute>
    2. added smart input in Asset and location section workorder page. i.e. after id="agajd"
    <field hide-label="true" padding="none" value="{woDetailResource.item.locationdesc ? woDetailResource.item.locationdesc : woDetailResource.item.locationnum}" id="agajd"/>
                          <smart-input on-change-arg="{{'page':page,'app':app}}" on-change="setassetlabel1" input-kind="YORN" value="{woDetailResource.item.gtassetlabel}" label="Is Asset Labeled?" id="wa38w"/>
    3. Added "setassetlabel1" function in appcustomization.js
    async setassetlabel1(event) {
        console.log("save on test label start ");
        let ds = event.page.datasources.woDetailResource;
        ds.save();
      console.log("save on test label end ");
      }
    4. I can see the field in preview mode in workorder page.


    It is editable. value is also changing when clicking there, but SAVE is not working.
    Could someone help with this scenario please?
    Thanks in Advance.


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


  • 2.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Wed November 22, 2023 05:44 PM

    Hi Ritesh,

    Can you try using the toggle component?

    <toggle label="Is Asset Labeled?" toggle-label-off="No" toggle-label-on="Yes" toggled="{woDetailResource.item.gtassetlabel}" type="TrueFalse" on-change-arg="{{'page':page,'app':app, 'item':woDetailResource.item}}" on-change="setassetlabel1"/>

    I also think that using Preview or Role Based App, Maximo won't understand what is gtassetlabel in the payload. So you may need to validate it on your on-change function. Something like below
    # Import the Device to your AppCustomizations.js
    import { Device } from '@maximo/maximo-js-api';
    
    
    async setassetlabel1(event) {
        console.log("save on test label start ");
        let ds = event.page.datasources.woDetailResource;
        if (Device.get().isMaximoMobile) {
            ds.item.asset.iscalibration = event.item.gtassetlabel;
        }
        ds.save();
      console.log("save on test label end ");
      }


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



  • 3.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Thu November 23, 2023 02:38 AM

    Hi Maycon,

    Thank you for the response.

    I tried putting the suggested code in AppCustomiation.js but got the compilation error related to import device as below. Am I doing something wrong?

    Failed to compile.

    ./src/AppCustomizations.js
    SyntaxError: /graphite/.workspace/WILSON-mx7vm/TECHMOBILE/build/app/src/AppCustomizations.js: Unexpected token (10:9)

       8 |
       9 |   // Import the Device to your AppCustomizations.js
    > 10 |   import {Device} from "@maximo/maximo-js-api";
         |          ^
      11 |



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



  • 4.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Thu November 23, 2023 02:54 AM

    I can see your error is at line 10. Is your import at the beginning of your AppCustomizations? What is your Mobile version?

    It should be:

    // Custom Application Logic
    importDevice } from '@maximo/maximo-js-api';

    class AppCustomizations
        YOUR CODE HERE
    }


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



  • 5.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Thu November 23, 2023 05:22 AM
    Edited by Ritesh Ranjan Thu November 23, 2023 05:23 AM

    Hi Maycon,

    Thanks, Compilation error is gone now. But save is not working.

    current value for that toggle is NO. once I click on that toggle, it becomes YES on the screen, but again it goes back to NO state.

    and save does not happen.

    Any idea?

    In developer tools, payload tab shows as below.

    and in preview tab, it shows gtassetlabel as false and same false value in response tab.



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



  • 6.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Thu November 23, 2023 05:14 PM

    Hi Ritesh,

    That was a condition mistake. My bad.

    Could you try replacing the if condition for the below condition?

    if (!Device.get().isMaximoMobile) {
            ds.item.asset.iscalibration = event.item.gtassetlabel;
        }

    It can be because of the relationship if it still does not work. Give it a try.



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



  • 7.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Fri November 24, 2023 12:46 AM
    Edited by Ritesh Ranjan Fri November 24, 2023 12:48 AM

    Hi Maycon,

    Unfortunately, this also did not work. 

    Do you have any other ideas to achieve this?

    I was thinking what if we create a new datasource with MXAPIASSET object structure (without relationship and depends-on main datasource) like below:

    <maximo-datasource id="assetlabelds" object-structure="mxapiasset">

    <schema>

    <attribute name="assetnum"/>

    <attribute name="siteid"/>

    <attribute name="iscalibration"/>

    </schema>

    </maximo-datasource>

    then we can call the save function in a similar manner. That should work because it worked for direct field of workorder object.

    But here I was not sure how to reference assetnum and siteid of workorder object. and how to display the correct value of that attribute on mobile screen.

    Any advice or any other alternative?

    FYI. I already tried with depends-on maximo datasource and tried calling save but it gave BAD POST REQUEST.  oslc#update_createuri.

    Thanks.



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



  • 8.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Fri November 24, 2023 01:17 AM

    It should work when using 

    <maximo-datasource depends-on="woDetailsResource" id="assetlabelds" id-attribute="assetnum" object-name="asset" relationship="asset" selection-mode="none">
    Check if the relationship is correct.
    You'll need to change your XML and JavaScript to use this new datasource, and also pass the assetlabelds in the on-toggle-arg.


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



  • 9.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Fri November 24, 2023 01:43 AM

    Hi Maycon,

    Tried your suggestions but did not work. :(

    code details are as below.

    Added below details in app.xml

    <!--Datasource-->
    
    <maximo-datasource object-name="asset" id="gtassetlabelds" relationship="asset" depends-on="woDetailResource" selection-mode="none" notify-when-parent-loads="true" id-attribute="assetnum">
              <schema id="bb7_y">
                <attribute name="assetnum" unique-id="true" id="kdv42"/>
                <attribute name="iscalibration--gtassetlabel1" id="b98m6"/>
                <attribute name="siteid" id="r_2kv"/>
              </schema>
            </maximo-datasource>
    
    
    <!--Toggle-->
    
    <toggle label="Is Asset Labeled Toggled?" toggle-label-off="No" toggle-label-on="Yes" toggled="{gtassetlabelds.item.gtassetlabel1}" type="TrueFalse" on-toggle-arg="{{'page':page,'app':app, 'item':gtassetlabelds.item}}" on-toggle="setassetlabel2" id="d_2g2"/>
    

    Then added setassetlabel2 function in appcustomiation.js as below:

    async setassetlabel2(event) {
        console.log("save on test toggle label2 startxyz ");
        let ds = event.page.datasources.gtassetlabelds;
        if (!Device.get().isMaximoMobile) {
            ds.item.iscalibration = event.item.gtassetlabel1;
        }
        ds.save();
      console.log("save on test label2 end ");
      }

    Then tried testing the same but got bad post request error in developer tools and in mobile preview, it will oslc#update_on_createuri as below.

    ASSET relationship details as below:

    Any suggestions??



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



  • 10.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Fri November 24, 2023 06:25 AM

    Hi @Steven Shull,

    Requesting your help here.



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



  • 11.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Mon November 27, 2023 12:19 AM

    Hi All,

    Please provide some guidance on this?

    Thanks in Advance.



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



  • 12.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Mon November 27, 2023 05:37 AM

    Hi Ritesh,

    You can try adding the assetuid to the data source, and changing the id-attribute. Last time I got this error was because it couldn't find the key attributes   

    Cheers. 



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



  • 13.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Mon November 27, 2023 10:22 PM

    The REST API requires the object data you're sending is part of the object structure for creating/updating records. Asset is not part of MXAPIWODETAIL because it should not be directly updated by a WO. Data that is not updated/created can be retrieved via relationship for display purposes even if it is not part of the object structure.

    There are pieces of asset updates (ex: downtime reporting and meter readings) that the core Maximo workflow supports that we've also enabled in mobile. But updates that are outside of that get into licensing issues. I may be wrong but I don't believe the iscalibration flag is a field we enable to be modified in the core WOTRACK application. Assuming that is correct, this functionality really needs to be added to the ASSETMOBILE application.

    A customer that enables the user to update asset fields in a WO based application may not need to grant the asset application to the user and thus they may not have the asset module counted as one of their modules. Since the Limited license is based on module count, that is a problem. Instead of 4 modules your user may show as only having access to 3 even though they're making updates to asset records. This would likely fall under the license circumvention (https://www.ibm.com/support/pages/licensing-information-and-usage-restrictions). 

    Ignoring the licensing aspect, what you would want to look at is the woassetmeters datasource and how we submit it in the WOUtil.js file with a put. That's a use case where we submit using a different object structure while still fetching the data with the WO. 



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



  • 14.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Tue November 28, 2023 04:52 AM

    Hi @Steven Shull,

    Thanks for the response.

    I had taken iscalibration flag just for an example.

    In our environment, we have a custom flag in Asset for updating label which needs to be shown in WO details page and also needs to be editable for technicians. That's why trying to implement the same.

    Are there no other way apart of custom controller?

    can't we make use of AppCustomization.JS file and custom-save option? or any other simple alternative?

    Thanks in Advance.



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



  • 15.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Tue November 28, 2023 07:40 AM

    The field being updated is irrelevant unless it's something we enable out of the box. It could be the asset description, the iscalibration flag, a custom field, etc. If it's part of another record (ASSET in this case) it shouldn't be added as modifiable to an application in another module.

    With that out of the way, there is no need for a custom controller. While we have controllers for the pages in TECHMOBILE that calls the update for meter readings, this same logic could easily be written in the AppCustomizations.js tied to an event (be it a button click or the toggle itself). There is potentially a cleaner way to do this, but using the assetmeter logic is an example of where we submit the transactions using another object structure which provides you the example you need.

    If you define your child datasource similar with mxapiasset for example (relationship="asset.mxapiasset"), and then build your update to it, you should be fine. I didn't use another object structure in this example but an example of a toggle I had used this logic (passing in the item as an argument). I think you should be able to do something similar. I don't have time to test this right now but it should get you what you need.

       async reviewTask(event)
       {
         let taskds = this.app.findDatasource('woPlanTaskDetailds');
         let item=event.item;
         if (item){
           let woTask={
              workorderid: item.workorderid,
              uo_taskreview: !item.uo_taskreview,
              href: item.href
           }       
           let option={
             responseProperties:"uo_taskreview",
             localPayload:{
                workorderid: item.workorderid,
                uo_taskreview: !item.uo_taskreview,
                href: item.href
             }
           }
           item.uo_taskreview=!item.uo_taskreview;
           await taskds.update(woTask,option);
           await taskds.forceReload();
         }
       }



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



  • 16.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Fri December 01, 2023 07:18 AM
    Edited by Ritesh Ranjan Mon December 04, 2023 02:35 AM

    Hi @Steven Shull,

    Thanks for the suggestion. I tried the below steps, but I think I am missing something.

    Created below child datasource within woDetailResouce datasource with relationship as asset.mxapiasset.

    <maximo-datasource auto-save="false" id="gtassetlabelds" relationship="asset.mxapiasset" object-name="asset" selection-mode="none" notify-when-parent-loads="true">
              <schema id="yraya">
                <attribute name="assetuid" id="vd7a8"/>
                <attribute name="siteid" id="j556k"/>
                <attribute name="assetnum" id="p6d8d"/>
                <attribute name="iscalibration--gtassetlabel" id="rvzrg"/>
                <attribute name="href" id="bm_jb"/>
              </schema>
            </maximo-datasource>

    then added a toggle in Asset and location section in workorder details page.

    <toggle label="Is Asset Labeled Toggled? review" toggle-label-off="No" toggle-label-on="Yes" toggled="{gtassetlabelds.item.gtassetlabel}" type="TrueFalse" on-toggle-arg="{{'page':page,'app':app, 'item':gtassetlabelds.item}}" on-toggle="reviewPlan" id="b9bar"/>

    Then Added below on-toggle event in appcustomization.js as below

    async reviewPlan(event)
       {
         console.log("save on reviewplan ");
         let labelds = event.page.datasources["gtassetlabelds"];
         let labeldetails={
              assetuid: labelds.item.assetuid,
              assetnum: labelds.item.assetnum,
              siteid: labelds.item.siteid,
              gtassetlabel: labelds.item.gtassetlabel
           }       
           let option={
             responseProperties:"assetnum, gtassetlabel, siteid ",
             localPayload:{
              assetuid: labelds.item.assetuid,
              assetnum: labelds.item.assetnum,
              siteid: labelds.item.siteid,
              gtassetlabel: labelds.item.gtassetlabel,
             } 
           }
           await labelds.update(labeldetails,option);
           await labelds.forceReload();
           console.log("save on test reviewplan end ");
       }  
    

    Now when I try to change the toggle , it still raise a POST request with mxapiwodetails instead mxapiasset, though in child datasource, asset.mxapiasset relationship has been defined. Any suggestions?

    Below URI I see is getting created in browser developer tools.

    http://localhost:3006/maximo/oslc/api/os/mxapiwodetail/_QkVERk9SRC8zNzUx/asset.mxapiasset?oslc.select=*&oslc.pageSize=20&collectioncount=1&ignorecollectionref=1&relativeuri=1&addschema=1&interactive=1&lean=1&internalvalues=1



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



  • 17.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Fri December 01, 2023 09:17 AM

    In Addition to previous notes, URI is getting created like below in developer tools.

    http://localhost:3006/maximo/oslc/api/os/mxapiwodetail/_QkVERk9SRC8zNzUx/asset.mxapiasset?oslc.select=*&oslc.pageSize=20&collectioncount=1&ignorecollectionref=1&relativeuri=1&addschema=1&interactive=1&lean=1&internalvalues=1


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



  • 18.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Mon December 04, 2023 02:38 AM

    Hi All,

    Any idea what I am missing here to make it work?

    Thanks in Advance.



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



  • 19.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Thu November 23, 2023 12:58 PM

    I tried the same approach for a checkbox /YORN field which is a direct attribute of workorder object. There the save method worked.

    but the same approach did not work for the iscalibration YORN field which came via "asset" relationship.

    wondering what else to be added in the code.



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



  • 20.  RE: Maximo Mobile - Have added a new smart-input as YORN in Asset and Location section from Asset table but custom save is not working

    Posted Thu November 23, 2023 05:30 AM

    Wanted to highlight one mroe thing..

    had to modify toogle snippet as below. In 8.10, with toggle on-change is not there. on-toggle is there so I have used that.

    <toggle label="Is Asset Labeled Toggled?" toggle-label-off="No" toggle-label-on="Yes" toggled="{woDetailResource.item.gtassetlabel}" type="TrueFalse" on-toggle-arg="{{'page':page,'app':app, 'item':woDetailResource.item}}" on-toggle="setassetlabel2" id="d_2g2"/>


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