In this document, you will find examples of PreSave Scripts, as well as how to utilize the script help feature as a field reference.
To access the script help feature, click the help button in the Security Script Manager.
This will open the Scripting Help pane on the right side of the screen where you will be able to access code examples, as well as search for in-scope variables and their respective names.
You may click the copy icon to the left of any code example or field to copy it to your clipboard. Fields will show not only the name used to access them, but also the data type. Using the autofilter row, you may search within this window to find fields easily.
Sales Document Entry PreSave
This pre-save script will stop the user from saving the document if a PO Number is not entered or a duplicate on a sales document.
//Check for duplicate Customer POs and warn customer if duplicate
if(sd.IsNew && sd.val_Sales_Doc_Type == "ORDER")
{
if (String.IsNullOrEmpty(Genframe4.Utils.ConvertToString(sd.val_Customer_PO_Num)))
{
e.Cancel = true;
return "Please enter a Customer PO number.";
}
else
{
SalesPad.Bus.SalesDocumentSearch sdsCheck = new SalesPad.Bus.SalesDocumentSearch();
sdsCheck.LightView = true;
System.SearchClause sc = new System.SearchClause(Bus.SalesDocument._Customer_PO_Num, Op.Equals, sd.val_Customer_PO_Num);
sc.And(Bus.SalesDocument._Sales_Doc_Num, Op.NotEquals, sd.val_Sales_Doc_Num);
List<string> sdResults = (sdsCheck.LoadList(sc, "Sales_Doc_Num")).ToList();
if (sdResults.Count > 0)
{
if (DialogResult.Yes != Messenger.AskYesNo("Customer PO number was used on: " + Genframe4.Utils.ConvertToString(sdResults[0]) + "\n\n Do you want to reuse it?"))
e.Cancel = true;
}
else
{
return "";
}
}
}
return String.Empty;
Customer Address Card PreSave
This Pre-Save will not allow a customer address to be saved unless a ZipCode is entered.
string message = "";
if (addr.val_Zip == "")
{
e.Cancel = true;
message += "Enter a Zipcode\n";
}
return message;
New Customer PreSave
This Pre-Save will not allow a new customer to be created without the Address Code field being set to BILL as the value.
string message = "";
if(SalesPad.Bus.CustomerAddr._Address_Code == "BILL")
{
e.Cancel = true;
message += "Enter a Customer Name\n";
}
return message;
The attached document below contains both examples as well as a list of available fields.