E: Own From: create work order

In this example a own modal window will be created

 

examplemodalwindow

 

- define new window

- change properties in the window

- create work order

 

Note:

two variants possible

- 1 script: all functionality defined in one script.  You define in this one script all functions for target window

- 2 scripts: 1.  script for opening the window, 2. script inside the new window for the logik

In this example the 1 script solution is described.

 

BSL: Workorder

WindowEvents form_opened

JBScript See openwindow, SQL, messagebox

 

jbscript-logo-small

#jbs

 
// create new form and open it 
let clform=application.openwindow({dwname:"createWorkorder",
  sql:'select space(1) as Tambor, space(10) as ItemCode1, 0.00 as peso1, space(10) as ItemCode2, 0.00 as peso2,space(10) as ItemCode3, 0.00 as peso3, space(10) as ItemCode4, 0.00 as peso4, space(10) as ItemCode5, 0.00 as peso5, space(10) as ItemCode6, 0.00 as peso6, space(10) as ItemCode7, 0.00 as peso7, space(10) as ItemCode8, 0 as peso8, space(10) ItemCode9, 0 as peso9, space(10) as ItemCode10, 0 as peso10 from "BEAS_DUMMY" ',
  form:{title:"Create Work order", height:2200} ,
 
 
   function:new function form_loaded(){
      // with function you define all events/functions for the new window      
      // in event "loaded" define all additional Properties
      dw_1.item.tambor.title="Tambor";
      dw_1.item.tambor.dropdown.values=["TAMBORO1","TAMBORO2","TAMBORO3"];
      dw_1.item.itemcode1.dropdown.sql='select "ItemCode" from "OITM" where "PrcrmntMtd"=\'M\' ';
      }
   
   } 
   ,{modal:true}
);
 
// This script is executed AFTER closing the window
// Note: It's possible to insert all checks in the modal form.
 
// Check, if form closed with OK
if(clform.returnOk==false) return -1;
 
// Check, if ItemCode is defined
if(clform.itemcode1=="") {
   messagebox("error","please insert item code");
   return -1;}
 
// Check, if item is existing
let r=sql.select count(*) from "OITM" where "ItemCode" = :clform.itemcode1 and "PrcrmntMtd" = 'M';
if (r==0) {
   messagebox("error","You can't use "+clform.itemcode1+" or item not existing");
   return -1;}
 
// Check quantities. Sum of all qty must be <= 50
let quantity=clform.peso1 + clform.peso2 + clform.peso3;
if (quantity>50) {
  messagebox("error","reduce total quantity");
  return -1;}
 

// in first "peso" field the qty must be defined
if (clform.peso1<=0) {
  messagebox("error","please insert quantity");
  return -1;}
 
// Create Work order
let w1=bsl.post("Workorder",{"WorkorderPos":[{"ItemCode":clform.itemcode1,"Quantity":clform.peso1}]});
if (w1.returnCode==-1){
   messagebox("error","Can't create work order "+w1.ret_value);
    return -1;}
// Convert String to Number
let wDocEntry=parseInt(w1.returnResult);
alert("Work order "+wDocEntry+" created");
 
return 1;

 

help-hinweis Example Notes