Previous Workorder Number

Hi,

I wondered if there was a way of getting the previous workorder associated with a unit without having to use unit.History and then stripping the text out. The ultimate aim is when the user has a workorder open they run a report which extracts pertinetent information for the current work order plus the service notes from last time. Realise that can right click the serial number form the service screen and then look at previous jobs and run a report that way, however attemtping to come up with a more elegant solution !!

Hi Martin, you could use the workoder service item list filtered by the Unit Id, just like you would do manually in the UI grid (though I don’t know if that’s an improvement over scraping the unit history), something like this:

Guid unitId = new Guid("{FC46F50E-7944-4B40-B307-59EE34145BD5}");

         WorkorderServiceItemList wisl = WorkorderServiceItemList.GetList("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?> 

" +
“<GRIDCRITERIA>
" +
" <COLUMNITEM CM=“aWorkorderService.aServiceDate” UI=“LT_WorkorderService_Label_ServiceDate” PIN=“0” WIDTH=“112” SORT=“ASC” />
" +
" <COLUMNITEM CM=“aWorkorderService.aServiceNumber” UI=“LT_O_Workorder” PIN=“0” WIDTH=“100” />
" +
" <COLUMNITEM CM=“aUnit.aSerial” UI=“LT_Unit_Label_Serial” PIN=“0” WIDTH=“292” />
" +
" <COLUMNITEM CM=“aWorkorderItemStatus.aName” UI=“LT_WorkorderItem_Label_WorkorderStatusID” PIN=“0” WIDTH=“158” />
" +
" <COLUMNITEM CM=“aWorkorder.aServiceCompleted” UI=“LT_Workorder_Label_ServiceCompleted” PIN=“0” WIDTH=“143” />
" +
" <COLUMNITEM CM=“aClient.aName” UI=“LT_O_Client” PIN=“0” WIDTH=“76” />
" +
" <COLUMNITEM CM=“aWorkorder.aOnsite” UI=“LT_Workorder_Label_Onsite” PIN=“0” WIDTH=“80” />
" +
" <COLUMNITEM CM=“aPriority.aName” UI=“LT_WorkorderItem_Label_PriorityID” PIN=“0” WIDTH=“83” />
" +
" <COLUMNITEM CM=“aUnitServiceType.aName” UI=“LT_O_UnitServiceType” PIN=“0” WIDTH=“131” />
" +
" <COLUMNITEM CM=“aWorkorderCategory.aName” UI=“LT_O_WorkorderCategory” PIN=“0” WIDTH=“149” />
" +
" <COLUMNITEM CM=“aDispatchZone.aName” UI=“LT_O_DispatchZone” PIN=“0” WIDTH=“120” />
" +
" <COLUMNITEM CM=“aWorkorderItem.aSummary” UI=“LT_WorkorderItem_Label_Summary” PIN=“0” WIDTH=“121” />
" +
" <COLUMNITEM CM=“aWorkorderItemType.aName” UI=“LT_WorkorderItem_Label_TypeID” PIN=“0” WIDTH=“153” />
" +
" <COLUMNITEM CM=“aUnitModel.aName” UI=“LT_O_UnitModel” PIN=“0” WIDTH=“101” />
" +
" <COLUMNITEM CM=“aUnitMeterReading.aMeter” UI=“LT_UnitMeterReading_Label_Meter” PIN=“0” WIDTH=“145” />
" +
" <WHEREITEMGROUP GROUPLOGICALOPERATOR=“And” UI=“LT_Unit_Label_Serial”>
" +
" <WHEREITEM COMPAREOPERATOR=“Equals” CM=“aWorkorderItem.aUnitID” UICOMPAREVALUE=”" TYPE=“System.Guid” COMPAREVALUE="{" + unitId.ToString().ToUpperInvariant() + “}” />
" +
"</WHEREITEMGROUP>
" +
"</GRIDCRITERIA> ");
MessageBox.Show(wisl.Count.ToString());

You can iterate them like this: foreach(WorkorderServiceItemList.WorkorderServiceItemListInfo i in wisl) { i.oneOfManyFieldsHere; //etc}

You can build a starter grid criteria in the UI then get the actual code to use by using the ctrl-alt-g command from the main grid. Remember this is Items so there could be dupes of the same workorder etc.