Maximo

Maximo

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

 View Only
  • 1.  Maximo Mobile datasource.update creates new records on Maximo

    Posted Fri January 19, 2024 03:37 AM

    Hi there!

    I've added to my TECHMOBILE app a WPSERVICE datasources to display, add, and edit a service item from mobile. I've tried to copy the reportworkLaborDetailds, and reportworkLabords functionalities when adding and editing a labour transaction. However, when performing a datasource.update(wpservice,options), it creates a new record on Maximo.

    Does anyone have an idea what is happening and why it is "duplicating" my item when trying to update it?

    <maximo-datasource depends-on="woDetailsReportWork" id="reportWorkServiceDetailsDs"  id-attribute="wpitemid" object-name="wpservice" relationship="showplanservice">
              <schema>
                <attribute name="wpitemid" searchable="true" unique-id="true"/>
                <attribute name="siteid"/>
                <attribute name="orgid"/>
                <attribute name="itemnum"/>
                <attribute name="description"/>
                <attribute name="itemqty"/>
                <attribute name="vendor"/>
                <attribute name="company.name--vendordesc"/>
                <attribute name="unitcost"/>
                <attribute name="itemsetid"/>
                <attribute name="orderunit"/>
                <attribute name="linetype" />
              </schema>
            </maximo-datasource>

    // Update code
    
    let serviceDs = evt.page.getDatasource('reportWorkServiceDetailsDs');
    
    let service = {
              itemnum: serviceDs.item.itemnum,
              itemqty: serviceDs.item.itemqty,
              description: serviceDs.item.description,
              unitcost: serviceDs.item.unitcost,
              orderunit: serviceDs.item.orderunit,
              vs_costtype: serviceDs.item.vs_costtype,
              vendor: serviceDs.vendor,
              vendordesc: serviceDs.vendordesc,
              vs_hirestart: hireStart,
              vs_hireend: hireEnd,
              linetype: serviceDs.item.linetype,
              linetype_description: serviceDs.item.linetype_description,
              anywhererefid: serviceDs.item.anywhererefid,
              itemsetid: serviceDs.item.itemsetid,
              wpitemid: serviceDs.item.wpitemid
            };
    
            let option = {
              responseProperties: 'wpitemid, anywhererefid',
            };
    
            try {
              this.page.state.useConfirmDialog = false;
              evt.page.state.loadingSaveService = true;
              evt.page.state.isSavedService = false;
              this.saveDataSuccessful = true;
    
              serviceDs.on('update-data-failed', this.onSaveServiceDataFailed.bind(this));
    
              await serviceDs.update(service, option);
    


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


  • 2.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Mon January 22, 2024 01:30 AM

    Hi Maycon,

    Did you check what kind of request it is generarting in developer tools in browser?

    Please check what is the value of x-methodoverride header in there.  It should have the value of "PATCH" to update an existing record.

    If it is not PATCH, try to change it to PATCH and then try updating.



    ------------------------------
    Ritesh Ranjan
    ------------------------------



  • 3.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Mon January 22, 2024 02:50 PM

    Hi Maycon,

    Try to put a new entry on your service json

    href: serviceDs.item.href

    I suspect, its creating a new record because api needs href reference



    ------------------------------
    Johnny Kubinhets Pedrozo
    ------------------------------



  • 4.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Mon January 22, 2024 11:38 PM
    Edited by Maycon Belfort Tue January 23, 2024 01:21 AM

    Thank you, Ritesh and Johnny, for your input. Here is what I have:

    X-Method-Override:PATCH
    Patchtype: MERGE
    Payload:
    [
        {
            "itemnum": "XXX1",
            "itemqty": 3,
            "description": "DESCRIPTION",
            "unitcost": 110,
            "orderunit": "CALLOUT",
            "vendor": "YYY",
            "vendordesc": "Yyyyy",
            "linetype": "STDSERVICE",
            "linetype_description": "Standard service",
            "anywhererefid": 1705879292107,
            "itemsetid": "ITEMSET1",
            "wpitemid": 6996060,
            "href": "http://childkey#V09SS09SREVSL1dQU0VSVklDRS82OTk2MDYw"
        }
    ]

    Response:

    {
        "_rowstamp": "[0 0 0 1 -95 -125 26 36]",
        "href": "api\/os\/mxapiwodetail\/_U0lURTAwMS9XNjQwMjY4Ng--",
        "wpservice": [
            {
                "_rowstamp": "[0 0 0 1 -95 -125 26 38]",
                "anywhererefid": 1705879292107,
                "wpitemid": 6996061,
                "localref": "api\/os\/mxapiwodetail\/_U0lURTAwMS9XNjQwMjY4Ng--\/showplanservice\/2-6996061",
                "href": "http:\/\/childkey#V09SS09SREVSL1dQU0VSVklDRS82OTk2MDYx"
            }
        ]
    }

    If I use datasource.save() instead of update, it works. However, it messes up the datasources when editing another item in the list.

    I have 2 datasources: id="reportWorkServiceDetailsDs" and id="reportWorkPlannedServiceDs".The first is what I use to edit and update/save the changes, and the second is what I display on my page.

    When editing an item, on my openDrawer method, I filter by the item on my details datasource to make the changes. After saving, I do a forceReload to my 2 datasources, so it will have the new items added or updated. But when opening a second item from the list, it can't find the item even after using the datasource.clearState(). Sometimes after saving the 2nd item, all records disappear from the list datasource (reportWorkPlannedServiceDs) or it leaves only the item I have changed.

    UPDATE

    After changing the log level to DEBUG, I can see this message on my console.

    2024-01-23T06:16:37.733Z: [ WARN]: [techmobile]: [UI-InfiniteLoader]: Render Failure.  We were told that we had 3 loaded items, but we only rendered 1 items.  This could be a bug in the Datasource, or we might have been triggered to re-render before we have loaded the data.



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



  • 5.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Tue January 23, 2024 01:31 AM

    Hi @Maycon Belfort,

    Payload part looks fine to me. (X-Method-Override:PATCH and Patchtype: MERGE).

    Help me to clarify few doubts:

    1. You are trying to have SERVICE feature similar to either MATERIAL or LABOR for creating a transaction record via sliding drawer??
    2. If yes, then you open a sliding drawer to add a new transaction/record for SERVICE??
    3. If yes, then what I am not able to understand that how or what you are trying to edit the saved record in SERVICE??



    ------------------------------
    Ritesh Ranjan
    ------------------------------



  • 6.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Tue January 23, 2024 02:05 AM

    Hi Ritesh

    1. Yes, but not servrectrans. It is the planned services wpservices. 
    2. Correct. 
    3. The user will have standard services that were created on Maximo before WO was assigned to them and they must update the existing ones or add new ones. 



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



  • 7.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Wed January 24, 2024 02:02 AM

    Here is what I got!

    It worked when changing from ds.update to ds.save. It adds the _buildid with the wpitemid and the _action: Change to the payload, so it's working now when updating an item.

    This is working fine on RBA, but on mobile, it has a different behaviour. On my 2 data sources, I have to force the reload to update the data on the screen. Still, it was causing some glitches when trying to add new items or edit others, so I noticed that I had to clean my details data source before searching on it again (when opening the drawer) using ds.clearState(), ds.resetState(), and ds.forceReload(). It seems that after filtering the ds, changing the filtered item and saving it, it temporarily removed the other items, so when trying to edit a different item, it couldn't find it even after forcing the reload after the save.
    I'll run more tests to certify it works, but it is likely solved.
    Thank you, @Ritesh Ranjan and @Johnny Kubinhets Pedrozo, for your help.


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



  • 8.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Wed January 24, 2024 02:52 AM

    Hi Maycon,

    Thanks for the info.

    are you gonna use this feature in Offline Mode also? if yes, is it working in offline mode?



    ------------------------------
    Ritesh Ranjan
    ------------------------------



  • 9.  RE: Maximo Mobile datasource.update creates new records on Maximo

    Posted Wed January 24, 2024 03:09 AM
    Yes, it works on offline mode as well. 

    Kind regards,
    Maycon Belfort