Maximo

 View Only

Understanding logic in WOListHandler.js, WorkExecution

  • 1.  Understanding logic in WOListHandler.js, WorkExecution

    Posted Thu July 13, 2023 11:33 AM
    Edited by System Tue August 22, 2023 04:41 PM

    UPDATE:

    After further debugging I can conclude that I get the [ERROR]workOrderSet is not defined from in OOTB Anywhere. In our case, as the spatial logic caused errors, ModelService.save(workOrderSet) is never called and I'm speculating that it could be the reason for several other issues.

    I can see that the render method in WOListHandler.js is very commonly used in the app.xml. Is this the method used for saving the WorkOrderSet in many cases? Saving the WO-set is the only thing done here aside from spatial operations.

    Thanks in advance,

    /John

    ------------------------------------------------------------Original Post-----------------------------------------------------------------

    Hi,

    In trying to get past an error that probably doesn't make any difference, I am confused as to why the logic works as it does.

    As we keep getting 

    [ERROR]TypeError: Cannot read properties of undefined (reading 'mobileMaximoSpatial')

        at Object.render (file:///data/user/0/com.skane.utv.maximoanywhere.trpexecution/files/www/js/application/handlers/WOListHandler.js:43:89)

    I tried to add logic to bypass the issue in the render function:

    render : function (eventContext) {
      // First if statement below added by me
    if (['platform.handlers.spatial.SpatialMapHandler'] in eventContext.application) {
    this.mobileMaximoSpatial =
    eventContext.application['platform.handlers.spatial.SpatialMapHandler'].mobileMaximoSpatial;
    if (this.mobileMaximoSpatial != null && this.mobileMaximoSpatial.sketchTool != null) {
    this.mobileMaximoSpatial.sketchTool.clearSketches();
    }
    }
    ModelService.save(workOrderSet);
    },
     
    Original Code:

    render : function (eventContext) {
    this.mobileMaximoSpatial =
             //Below is the line it's complaining about:
    eventContext.application['platform.handlers.spatial.SpatialMapHandler'].mobileMaximoSpatial;
    if (this.mobileMaximoSpatial != null && this.mobileMaximoSpatial.sketchTool != null) {
    this.mobileMaximoSpatial.sketchTool.clearSketches();
    }
    ModelService.save(workOrderSet);
    },
    When I nest the logic in my if statement and rebuild the app, suddenly workOrderSet is undefined. What? Why is it undefined now, it's not defined in the function in the original code anyway. Why does my if statement make any difference? Does declaring the this keyword outside of an if statement make workOrderSet accessible somehow, even though it is referencing something else? Thankful for some insight here, and help in solving this kind of issue.

    I'm attaching the whole edited js-file in this post for those that are interested.

    Thanks,

    /John Venkiah



    ------------------------------
    John Venkiah
    Application Developer
    IBM CIC Sweden
    John.Venkiah-CIC@ibm.com
    ------------------------------


    #MaximoAnywhere
    #Maximo