IBM Support

Creating a Work Order and approving it using Maximo REST.

Technical Blog Post


Abstract

Creating a Work Order and approving it using Maximo REST.

Body

Last week I made a blog regarding logging data in Maximo using a Raspberry Pi. The point was to show how to enter data in Maximo with an IOT device using Node-Red. That got me thinking about using the Raspberry Pi to create a Work Order just in case something needed to be investigated or fixed. For example, if the temperature in a room rise above a certain degree, you might want to send someone out to have a look at the room. It's easy to use the REST API to create a Work Order but it's a little bit more complicated to approve it. To approve it, you cannot just update the Work Order, you will have to use a WebService which is handled a little bit different in REST. The Sense Hat on the Raspberry PI has a joystick that has a built in button. In my example, I will create a Work Order when the button is pressed. Here is the Node-Red Process,

image

 

 

The first two nodes test the Joystick and if it is pressed it sends a command to the Create Work Order Node. In this case the command is ignored but you could for example include data such as the temperature or any other reason the Work Order is generated. Let's have a look at the Create New Work Order node,

  // Generic parameters...  maximoIP = "192.168.0.20";  maximoUser = "wilson";  maximoPassword = "wilson";  maximoSite = "BEDFORD";  maximoDescription = "Workorder from Raspberry Pi";  maximoLocation = "PISTORAGE";    // Save for nodes further down the process.  msg.maximoIP = maximoIP  msg.maximoUser = maximoUser  msg.maximoPassword = maximoPassword    // Construct URL to create new Work Order. Specify format to be JSON when the new Work Order is returned.  msg.url="http://" + maximoIP + "/maxrest/rest/mbo/workorder?_lid=" + maximoUser + "&_lpwd=" + maximoPassword +  "&_compact=true&_format=json&description=" + maximoDescription + "&siteid=" + maximoSite + "&location=" + maximoLocation;  // To create new record, use the PUT method.  msg.method="PUT";    return msg;

The first part is the parameters, SiteID for the Workorder, description and Location. Then we save parameters for the node further down the process. The last part generates an URL such as,

http://[Maximo_IP]/maxrest/rest/mbo/workorder?_lid=wilson&_lpwd=wilson&_compact=true&_format=json&description=Workorder from Raspberry Pi&siteid=BEDFORD&location=PISTORAGE

Here we just specify that we want to use the Workorder mbo for REST and then we specify description, site and location. Since the msg.method is PUT, Maximo will create a new Work order with these parameters.

The next node, REST Create WO, will send the HTTP request, the WO is created and the data for the new Work Order is returned. The data is then converted to JSON and passed into the Change Status node.

  // The new Work order is returned after it has been created so we can grab the ID from there.  workorderid = msg.payload.WORKORDER.WORKORDERID    // We want to change the status to apporved and also add a memo.  maximoStatus = "APPR";  maximoMemo = "Status change from the Maximo REST API";    //Get saved parameters.  maximoIP = msg.maximoIP;  maximoUser = msg.maximoUser;  maximoPassword = msg.maximoPassword;    // Construct the URL, this time we need to use the ID returned for the Workorder.  // We also specify the new status and memo, along with the &~wo=this parameter which tells us to change this specific Workorder.  // Since the staus and memo parameters belong to a web service they have a tilde prefix.  msg.url="http://" + maximoIP + "/maxrest/rest/mbo/workorder/" + workorderid + "?_lid=" + maximoUser + "&_lpwd=" + maximoPassword +  "&_compact=true&_format=json&~status=" + maximoStatus + "&~memo=" + maximoMemo + "&~wo=this";  // Use the POST method to update the Workorder.  msg.method="POST";  // Since we want to invoke a WebMethod, we need to set a header with the specific method we want to invoke, in this case changeStatus.  msg.headers = { "x-http-method-override" : "changeStatus" };  return msg;

Here we grab the unique ID for the Work Order and set some parameters for the status change. We grab the parameters we passed down earlier and then we construct a URL such as,

http://[Maximo_IP]/maxrest/rest/mbo/workorder/[Unique_ID]?_lid=wilson&_lpwd=wilson&_compact=true&_format=json&~status=APPR&~memo=Status change from the Maximo REST API&~wo=this

Here we specify the unique ID (1971) in the URL since that is the Work Order we want to change, the status changing parameters are also specified but they are prefixed with a tilde, ~ since they are parameters for the Web Method. The ~wo=this is a special case referring this Work Order which is the Work Order we want to change status for. To specify the actual WebMethod we need to use a header with the x-http-method-override parameter set to changeStatus, which is the WebMethod in Maximo we want to call. Finally we set the Method to POST to flag the update and status change.

The trickiest part here was to figure out how to use the WebMethods, hopefully this was a good example on how to use the WebMethods in REST.

Here is the full Node-Red process,

  [{"id":"53da8aee.3d6ef4","type":"function","z":"7dc9288.7e2add8","name":"Create New Work Order.","func":"// Generic parameters...\nmaximoIP = \"192.168.0.20\";\nmaximoUser = \"wilson\";\nmaximoPassword = \"wilson\";\nmaximoSite = \"BEDFORD\";\nmaximoDescription = \"Workorder from Raspberry Pi\";\nmaximoLocation = \"PISTORAGE\";\n\n// Save for nodes further down the process.\nmsg.maximoIP = maximoIP\nmsg.maximoUser = maximoUser\nmsg.maximoPassword = maximoPassword\n\n// Construct URL to create new Work Order. Specify format to be JSON when the new Work Order is returned.\nmsg.url=\"http://\" + maximoIP + \"/maxrest/rest/mbo/workorder?_lid=\" + maximoUser + \"&_lpwd=\" + maximoPassword +\n\"&_compact=true&_format=json&description=\" + maximoDescription + \"&siteid=\" + maximoSite + \"&location=\" + maximoLocation;\n// To create new record, use the PUT method.\nmsg.method=\"PUT\";\n\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":140,"wires":[["95d1b221.fc7ed"]]},{"id":"95d1b221.fc7ed","type":"http request","z":"7dc9288.7e2add8","name":"REST Create WO","method":"use","ret":"txt","url":"","tls":"","x":390,"y":140,"wires":[["4ec07900.a0cbf8"]]},{"id":"accd6cde.acc2f","type":"debug","z":"7dc9288.7e2add8","name":"","active":true,"console":"false","complete":"false","x":1050,"y":280,"wires":[]},{"id":"8014dd2e.c0eee","type":"function","z":"7dc9288.7e2add8","name":"Change status.","func":"// The new Work order is returned after it has been created so we can grab the ID from there.\nworkorderid = msg.payload.WORKORDER.WORKORDERID\n\n// We want to change the status to apporved and also add a memo.\nmaximoStatus = \"APPR\";\nmaximoMemo = \"Status change from the Maximo REST API\";\n\n//Get saved parameters.\nmaximoIP = msg.maximoIP;\nmaximoUser = msg.maximoUser;\nmaximoPassword = msg.maximoPassword;\n\n// Construct the URL, this time we need to use the ID returned for the Workorder.\n// We also specify the new status and memo, along with the &~wo=this parameter which tells us to change this specific Workorder.\n// Since the staus and memo parameters belong to a web service they have a tilde prefix.\nmsg.url=\"http://\" + maximoIP + \"/maxrest/rest/mbo/workorder/\" + workorderid + \"?_lid=\" + maximoUser + \"&_lpwd=\" + maximoPassword +\n\"&_compact=true&_format=json&~status=\" + maximoStatus + \"&~memo=\" + maximoMemo + \"&~wo=this\";\n// Use the POST method to update the Workorder.\nmsg.method=\"POST\";\n// Since we want to invoke a WebMethod, we need to set a header with the specific method we want to invoke, in this case changeStatus.\nmsg.headers = { \"x-http-method-override\" : \"changeStatus\" };\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":140,"wires":[["50ec24fb.4d41fc"]]},{"id":"4ec07900.a0cbf8","type":"json","z":"7dc9288.7e2add8","name":"Convert to JSON","x":610,"y":140,"wires":[["8014dd2e.c0eee"]]},{"id":"50ec24fb.4d41fc","type":"http request","z":"7dc9288.7e2add8","name":"REST Change Status","method":"use","ret":"txt","url":"","tls":"","x":1040,"y":140,"wires":[["accd6cde.acc2f"]]},{"id":"310b02d7.9d480e","type":"rpi-sensehat in","z":"7dc9288.7e2add8","name":"Joystick","motion":false,"env":false,"stick":true,"x":100,"y":60,"wires":[["1dadea76.df0236"]]},{"id":"1dadea76.df0236","type":"switch","z":"7dc9288.7e2add8","name":"Test Joystick Button","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":1,"x":300,"y":60,"wires":[["53da8aee.3d6ef4"]]}]

 

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSLKT6","label":"IBM Maximo Asset Management"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11130637