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
Original Message:
Sent: Thu August 08, 2024 06:07 AM
From: Alessandro Di Maggio
Subject: Maximo Mobile set datasource fields via customization
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
Original Message:
Sent: Tue June 04, 2024 08:50 AM
From: Steven Shull
Subject: Maximo Mobile set datasource fields via customization
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
Original Message:
Sent: Sun June 02, 2024 09:31 AM
From: Alessandro Di Maggio
Subject: Maximo Mobile set datasource fields via customization
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
------------------------------