Maximo

 View Only
  • 1.  Maximo Mobile set datasource fields via customization

    Posted Mon June 03, 2024 10:18 AM

    Hi there.

    in my TECHMOBILE app I've "extended" the MXAPIWODETAIL in order to include a custom table.
    Now I'm trying to create a slide in the app mobile to create a new record in that table. 
    The issue here is that I want to set an attribute of the datasource that is shown in the custom Drawer equal to the wonum of the woactivity.

    This is the code that is evoked pressing the "open drawer" button:

      async showcustomMbo(evt) { 
        let dscustMbo = evt.page.getDatasource['cMboDs'];
        let wo = evt.page.datasources['woPlanTaskDetailds'];
        dscustMbo.item['record'] = '';
        dscustMbo.item['wonum']=wo.item.wonum
        this.page.showDialog('customDrawer');
      }
    I want the attribute "record" to be set to null as well when opening the dialog. But what I wrote seems not to be working.
    Thank you for you help.


    ------------------------------
    Alessandro Di Maggio
    ------------------------------


  • 2.  RE: Maximo Mobile set datasource fields via customization

    Posted Tue June 04, 2024 08:50 AM

    You mention that this is a custom table but it's not clear to me if this is a 1:1 to WO/task (like service address) or 1:many (like actual materials) where you may need a new record to be added. If you are creating a new record in your child object, make sure you have ANYWHEREREFID on the object and on the datasource. This helps ensure that we can map the record created on the device with a response from the server. And then you would call .addNew() on the datasource like:

    let item=await dscustMbo.addNew();
    item.record="";

    In addition, the woPlanTaskDetailds is going to have an array of tasks but you'll be grabbing a random one when you go back to the datasource. You'll need to pass in the specific task to the showcustomMbo event. I assume this is an on-click so you'd need to have something like:

    on-click-arg="{{'item': woPlanTaskDetailds.item}}"

    You should also never access datasources using the page. You should always access it from the app like:

    laborDs=this.app.findDatasource("woLaborDetailds");

    Whether the datasource is page or app scoped, this works. Being consistent alone is a good reason to use this approach. JavaScript makes it impossible to prevent customers from using unsupported APIs which is why you can do it but the page.datasources approach is not an intended API for customers to use. This is something we may break at any point in the future. 


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



  • 3.  RE: Maximo Mobile set datasource fields via customization

    Posted Thu August 08, 2024 06:07 AM

    Hi Steven,

    I've tried changing the code as it follows but I dont seem to be able to make it work yet. Now the record created is a completely new record, but it doesn't inherit the attribute I'm trying to make him inherit.
    Here's a snippet of the code I'm trying to work with:

      async showDialogCustom(evt) {

        let dsAno = evt.page.datasources["cNewAnDsTasks"];
        let wo = evt.item
        let asset= evt.assetnum
        let item=await dsAno.addNew();
        item["assetnum"]=asset; 
        item.wonum=wo.wonum; //Here I've been trying two different approaches, hoping it would make the difference.
        this.page.showDialog("cAnDrawerTasks");
      }
    And here the "button" that recall that function:
    <button id="buttonTest1" icon="maximo:inspections" on-click="showDialogCustom" on-click-arg="{{'item':woPlanTaskDetailds.item,'datasource':woPlanTaskDetailds,'page':page,'app':app}}"/>
    I've been trying different approaches but it doesn't seem like working in any way. I want to take the value of the "assetnum" and "wonum" of the task I'm clicking on via the button and set these values in the assetnum and wonum attribute of the "cNewAnDsTasks" datasource.
    Thanks again for your help.


    ------------------------------
    Alessandro Di Maggio
    ------------------------------



  • 4.  RE: Maximo Mobile set datasource fields via customization

    Posted Mon August 12, 2024 09:40 PM

    There's a couple of key concepts here. First, when you pass in a datasource item like this:
    'item':woPlanTaskDetailds.item

    Think of it as a static mapping to the active item in the datasource. Unless you only have 1 record in the datasource (which is not typically the case on a datasource like tasks) you're going to get the wrong record passed into your method. What you want is your button to exist in the data-list and pass in the item. Example of what we do in the completeWoTask method

    on-click="completeWoTask" on-click-arg="{{'taskItem': item, 'status':'COMP', directlyCompleteWoTask : true}}"

    Notice how it's just 'taskItem': item and not woPlanTaskDetailds.item. That's intentional so if we click it on task 10 we pass in a different record than task 20. This is on me because I mistakenly had it in my example even though I was explaining the problem that you would get back a random item. 


    Second you reference evt.assetnum but don't pass in assetnum as a parameter. In this specific case I wouldn't recommend doing that because you're passing in the item itself and can access anything you need from that. In your example, you would want to say let asset=wo.assetnum for example.


    Third, I mentioned this before, but you should never access datasources directly on the app or page. You should always use this.app.findDatasource("cNewAnDsTasks"). I know you'll see some out of the box examples. And because it's JavaScript, we can't prevent it, but we don't want nor intend for developers to access the datasources on the page or app directly like that. We talk about this on the development best practices section of the "Developing with Graphite" section in the Developer Documentation link in the config tool. 

    Lastly, can you share how your datasource cNewAnDsTasks is defined? Specifically, what (if any) is the parent datasource? On Maximo Mobile, we don't officially support 3 level datasources (IE cNewAnDsTasks being a child of woPlanTaskDetailds which is a child of woDetailResource). We talk about this on the multi-level datasources page in 9.0. That's possibly your issue here but I'm not as familiar with the issues & limitations here because I haven't had to build out a use case like this yet. 



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