HPSM – Change Auto Closure


Hi all, today I’d like to share with you a script (in JavaScript code) I created to force Change records, it can be used for several purposes, in my case I wanted to close all old Changes stuck in a specific phase (I omitted to write the full query, you could set any query you want depending on your needs).

Please remember that you can execute this script via Schedule, Script Library, Process, Script or anything else you prefer 😉

function CloseChange(query)
{
  var fChm= new SCFile("cm3r");
  var rc = fChm.doSelect("query);
  if (rc == RC_SUCCESS)
  {
    while (rc == RC_SUCCESS)
    {
      fChm.status="closed"
      fChm.open=false;
      var arrDesc = new Array();
      arrDesc.push("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
      arrDesc.push(system.functions.tod().toString() + " - Change Closed by system");
      arrDesc.push("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
      arrDesc.push("");
      var lng = fChm.description.length();
      for (i = 0; i < lng; i++)
      {
        arrDesc.push(system.functions.nullsub(fChm.description[i], ""));
      }
      fChm.description = arrDesc;
      fChm.close_time = system.functions.tod();
      fChm.doUpdate();
      CreateApprovalLog(fChm);
      print("Change " + fChm.number + " closed by system.");
 
      rc = fChm.getNext();
    }
  }
}

//function to create the ApprovalLog record
function CreateApprovalLog(record)
{
  var fApp = new SCFile("ApprovalLog");
  fApp.file_name = "cm3r";
  fApp.unique_key = record.number;
  fApp.category = record.category;
  fApp.current_phase = record.current_phase;
  fApp.action = "CLOSE";
  fApp.date = system.functions.tod();
  fApp.operator = "SYSTEM";
  fApp.operator_fullname = "SYSTEM CLOSURE PROCESS";
  var arrComm = new Array();
  arrComm.push("Change moved to closed status.");
  fApp.comments = arrComm;
  fApp.doInsert();
}

As you can see in the previous code, I created also a CreateApprovalLog() function in order to create the activity for the changes being closed by this script (if you don’t need it, you can skip the row which calls this function).

Cheers and enjoy the code 😉

Tagged with: , , , ,
Posted in HPSM, JavaScript

Leave a comment

Support this blog

Hi, first of all thank you for visiting my blog!

As you probably already noticed, this blog is completely accessible and free, there's no restricted content and everybody can find info about HP Service Manager.

I spend most of my free time trying to do my best to help people in trouble with technical topics on HPSM (plus some more general articles). If you find my articles interesting, know that you can support my work by donating using the button below - this will encourage me to go ahead with new articles ;-)

Thanks in advance!

Donate Button with Credit Cards

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 40 other subscribers