Screen Data Script     


This is related to Master, Order, Receiving, and Invoicing Screens where the action of Adding or Deleting a record or changing any field within the record will automatically run the Script to provide a resultant action.  For example

Zero Price Check on Sales Order Lines

Update Sell Price based on Last receipt Cost

In Purchasing check for best price from all Suppliers

Have a pop-up Sales Message appear

Specify a minimum order quantity

Show active Promotion when Sales Line Entered

 

To see how this works we will create a Custom Script that will block any Price or Cost change to an Order Line if the resultant margin falls below the value defined in the System Settings screen.

 

Go into File>System Configuration>System Settings and amend field ‘Min Allowable Margin%’ to 50.  

 

Now, go to File>Custom Scripts and add a new Custom Script called (say) Margin Check and ‘check’ the ‘This is a Screen Data script’ checkbox.  Click on the ‘Script’ tab and add the following script

 

var

TheMinMargin,TheUnitPrice,TheUnitCost,TheCalcMargin: double;

TheIntValueofMargin: integer;

begin

TheMinMargin := GetDoubleFromTable('SYSTEMMASTER','MINMARGINPERCENT','COMPANYACCOUNTINGID','100');

TheUnitCost := GetCost(queryvalue('CODETYPE'),queryvalue('LINECODE'));

TheUnitPrice := strtofloat(queryvalue('ORDERUNITPRICE'));

if (TheUnitPrice <> 0) then

  begin

    TheCalcMargin := (((TheUnitPrice - TheUnitCost)/ TheUnitPrice) * 100);

    if (TheCalcMargin < TheMinMargin) then

     begin

      TheIntValueofMargin := int(TheCalcMargin * 100);

      TheCalcMargin := (TheIntValueofMargin /100);

      messagedlg('A ' + floattostr(TheCalcMargin) + ' % margin is below the Company Minimum of ' + floattostr(TheMinMargin) + ' %',mtinformation,mbOK,0);

      {Comment out the abort function below if you just want to display a message only}

      abort;

     end

  end

else

  begin

   if (TheUnitCost > 0) then

     messagedlg('This line has a Zero Price with a Cost',mtinformation,mbOK,0);

  end;

end.

 

Save and exit the Custom Script screen.

 

The next step is to tell Ostendo that the script is linked to a Sales Order Line.  To do this go into File>System Configuration>Screen Data Scripts and create a new record containing the following

Screen:  Select ‘Sales Orders’ from the drop-down

Table Name:  Select ‘SALESLINES’ from the drop-down list

SQL Type: Select ‘Insert

Script Name: Select the above script Name

Save and exit

 

Now go into Sales>Sales Orders and create a Sales Order then add a line to the Order.  If you amend the sell price against the Item such that the resultant price falls below the above Margin then you will get a message returned and you will be prevented from saving the line.

 

This covers the situation where you are adding a new Sales Order Line but what about if you are amending an existing line.  This can be covered by going back into File>System Configuration>Screen Data Scripts and create another record containing the following

Screen:  Select ‘Sales Orders’ from the drop-down

Table Name:  Select ‘SALESLINES’ from the drop-down list

SQL Type: Select ‘Update

Script Name: Select the above script Name

Save and exit