Creating a work order

In this example a button is added in the Item Structure window. When this button is clicked a dialog box is shown where the quantity can be entered and a work order is created for the selected item and provided quantity.

 

1.Open the Item Structure from Inventory>Item Structure.
2.Open the beas script editor from Tools>Extension for Clients or use the CTRL+N+U shortcut.
3.In the editor enter the code to create a new button. See, create for more details.
global function form_loaded
  create button=name=createwo,text=Create WO
end global
4.Add the event to the new button similar to exmple Add a button and click event.
global function dw_master_item_button_createwo_click
 
end global
5.Within the event, open the Script Assistant and choose the open own and special windows command, then fill in the form and include the SQL query. The code is inserted into the event.
Script Assistant Details

Script Assistant Details

 
global function dw_master_item_button_createwo_click
 
  // open own edit window
  declare=clform=ue_form
  clform.name=fast_wo_creation
  clform.title=Fast WO creation
  clform.sql=select top 1 '<dw_1.item.itemcode.value>' as itemcode, 1 as quantity from "BEAS_DUMMY"
  clform.style=edit
  // Default update function is disabled. With the following line you can activate this
  // clform.update=true
  // show window as dialog. if you want only to open this, use "clform.show"
  clform.showdialog
  // create WO code to be added
  destroy=clform
end global

6.Add the code to create the WO.
if <clform.ret_code> n= 1 then
//Validation is added in next step here.
  setvar=ls_itemcode=<clform.itemcode>
  setvar=ll_quantity=<clform.quantity>
declare=mywo=ue_api_wo
mywo=new
mywo=line=itemcode=<ls_itemcode>
mywo=line=quantity=<ll_quantity>
mywo=add
destroy mywo
end if
7.Add validation to check whether the selected item is a production item. WO is only created if this is true.
  //Before we create the work order we validate that selected item is a production item
  select count(*) from "OITM" where "ItemCode" = <ls_itemcode,dbstring> and "PrcrmntMtd" ='M'
  if <wert1> n= 0 then
    messagebox=Item is not a manufactring item
    return failure
  end if

 

The full code:

global function form_loaded
   create button=name=createwo,text=Create WO
end global
 
global function dw_master_item_button_createwo_click
// open own edit window 
declare=clform=ue_form 
clform.name=fast_WO_creation 
clform.title=Fast WO creation 
clform.sql=select top 1 '<dw_1.item.itemcode.value>' as itemcode, 1 as quantity  from "BEAS_DUMMY" 
clform.style=edit 
// Default update function is disabled. With the following line you can activate this 
// clform.update=true 
// show window as dialog. if you want only to open this, use "clform.show" 
clform.showdialog
 
if <clform.ret_code> n= 1 then 
   setvar=ls_itemcode=<clform.itemcode>
   setvar=ll_quantity=<clform.quantity>
 
   //Before we create the work order we validate that the selected item is a production item
   select count(*) from "OITM" where "ItemCode" = <ls_itemcode,dbstring> and "PrcrmntMtd" = 'M'
   if <wert1> n= 0 then
      messagebox=Item is not a manufacturing item
      return failure
   end if
 
declare=mywo=ue_api_wo
   mywo=new
   mywo=line=itemcode=<ls_itemcode>
   mywo=line=quantity=<ll_quantity>
   mywo=add
   destroy mywo
end if
 
destroy=clform
 
end global

The end result is a button in the Item Structure window, which requests the item quantity to be produced when clicked.

fast_create_WO
If the requested item is not a production item a message is displayed, otherwise a new work order is created.

fast_create_WO_error