Maximo Open Forum

 View Only

 Autoscript : changestatus not working, but no log to explain

  • Administration
  • Customizations
Kévin SUBIRATS's profile image
Kévin SUBIRATS posted 03-01-2024 23:27

Hello there

I've got a script with a launch point as Action, and triggered by Workflow process.

To get it simple, Service Request are in a Waiting Node and when the status change, it create a task : depending the answer of user, Work and Solution on Workorder is accepted or not.

I've got all the logs, but still, even if the script goes through the ChangeStatus method, it's not doing anything.

Here's the script (sorry I'm French)

// Autoscript SRWOTRAVTERMREF : ALBIOMA - Refus des travaux terminés des BT depuis la DS

// launchpoint : SRWOTRAVTERMREF type=ACTION, objectname=SR

// lors de la sauvegarde d'une SR, on propage les statuts uniquement pour la partie CTRL.
// historique
// V1.0 : 19/02/2024 version initiale
// V2.0 : 01/03/2024 passage en Nashorn et modification complete de l'algorithme

// definition des variables de classe en dehors du Try pour les rendre accessible dans le Finally
var MXServer = Java.type("psdi.server.MXServer");

// variables du MBO actuel
var vTicketID = mbo.getString("TICKETID");
// variables reutilisables
var vMemo = "Refus de validation des travaux traitant la DS " + vTicketID;

main();

function main() {
    // definition des variables de classe en dehors du Try pour les rendre accessible dans le Finally
    var MXServer = Java.type("psdi.server.MXServer");
    var woSet= Java.type("psdi.mbo.MboSet");
    try {
        if(mbo.getString("STATUS") == "TRAVTERMCTRL"){
            // recuperation du mbo WORKORDER via RELATEDRECORD
            woSet = mbo.getMboSet("RELATEDWOVIARR");
            if (woSet.isEmpty()){
                service.log_info("Aucun BT lie a la DS "+ mbo.getString("TICKETID") + " ; Probleme de coherence de donnees et de statut.");
            } else {
                // positionnement sur le premier MBO du set
                wo = woSet.moveFirst();
                // Traitement
                while (wo){
                    // si le statut du BT permet un traitement
                    if (wo.getString("STATUS") == "TRAVTERMCTRL" || wo.getString("STATUS") == "TRAVTERM"){
                        // le BT passe a TRAVTERMREF
                        wo.changeStatus("TRAVTERMREF", MXServer.getMXServer().getDate(), vMemo);
                        service.log_info("BT " + wo.getString("WONUM") + " lie a la DS "+ mbo.getString("TICKETID") + " passe au statut TRAVTERMREF");
                    } else {service.log_info("BT " + wo.getString("WONUM") + " au statut " + wo.getString("STATUS") + ", lie a la DS "+ mbo.getString("TICKETID") + " au statut " + mbo.getString("STATUS") + " non traitable");}
                    wo = woSet.moveNext();
                }
            }  
        }
    } finally {
        service.invokeScript("ALBIOMA.SCRIPT.LIBRARY").close(woSet);
    }
}
Kévin SUBIRATS's profile image
Kévin SUBIRATS

Well, I found by myself : I have to save the woset... It was so obvious I spend hours on it.

I found the solution using this forum, so thanks everybody for sharing such good infos.