No edit summary |
|||
Line 85: | Line 85: | ||
* Do Calculation Qty := UDF_Length * UDF_Width * UDF_Rate | * Do Calculation Qty := UDF_Length * UDF_Width * UDF_Rate | ||
Last Script Update : | Last Script Update : 23 Oct 2017<br /> | ||
Level : Basic | Level : Basic | ||
Line 151: | Line 151: | ||
for i:=0 to DataSet.FieldDefs.Count-1 do begin | for i:=0 to DataSet.FieldDefs.Count-1 do begin | ||
AFld := DataSet.FieldDefs.Items[i].Name; | AFld := DataSet.FieldDefs.Items[i].Name; | ||
if Copy(AFld, 1, Length('UDF_')) = 'UDF_' then begin // Set UDF Value | DataSet.Edit; // Make sure is in Edit Mode | ||
if Copy(AFld, 1, Length('UDF_')) = 'UDF_' then begin // Set UDF Value | |||
if CheckAvailFld(cdsData, AFld) then | if CheckAvailFld(cdsData, AFld) then | ||
DataSet.FindField(AFld).AsString := cdsData.FindField(AFld).AsString; | DataSet.FindField(AFld).AsString := cdsData.FindField(AFld).AsString; | ||
Line 161: | Line 162: | ||
begin | begin | ||
// Below is doing calculation for Qty := UDF_Length * UDF_Width * UDF_Rate | // Below is doing calculation for Qty := UDF_Length * UDF_Width * UDF_Rate | ||
DataSet.Edit; // Make sure is in Edit Mode | |||
DataSet.FindField('Qty').AsFloat := DataSet.FindField('UDF_Length').AsFloat * | DataSet.FindField('Qty').AsFloat := DataSet.FindField('UDF_Length').AsFloat * | ||
DataSet.FindField('UDF_Width').AsFloat * | DataSet.FindField('UDF_Width').AsFloat * | ||
Line 477: | Line 479: | ||
Remember to Enable Back by Disable the GetAuthorised (see below) Script & Insert it to '''OnBeforeNew''' script<br /> | Remember to Enable Back by Disable the GetAuthorised (see below) Script & Insert it to '''OnBeforeNew''' script<br /> | ||
Cons : It will be delay about | Cons : It will be delay about <span style="color:#0000ff">3 to 4 sec.</span> after click Edit & New button | ||
Last Script Update : 03 Nov 2015<br /> | Last Script Update : 03 Nov 2015<br /> | ||
Line 654: | Line 656: | ||
* Create a drop down list at Maintain Customer for UDF_SearchKey | * Create a drop down list at Maintain Customer for UDF_SearchKey | ||
Last Script Update : | Last Script Update : 26 Mar 2018<br /> | ||
Level : Advance | Level : Advance | ||
Line 681: | Line 683: | ||
procedure Setup; | procedure Setup; | ||
begin | begin | ||
cdsSearchKey := TClientDataset.Create(nil); | dsSearchKey := TDataSource.Create(nil); | ||
cdsSearchKey := TClientDataset.Create(nil); | |||
grGrid1 := TcxGrid.Create(nil); | |||
end; | |||
procedure FreeCmpt(lComponent :TObject); | |||
begin | |||
if Assigned(lComponent) then | |||
lComponent.Free; | |||
end; | end; | ||
procedure TearDown; | procedure TearDown; | ||
begin | begin | ||
cdsSearchKey | FreeCmpt(cdsSearchKey); | ||
FreeCmpt(dsSearchKey); | |||
FreeCmpt(gvSearchKey); | |||
FreeCmpt(grGrid1); | |||
end; | end; | ||
Line 748: | Line 762: | ||
begin | begin | ||
M := TDataSource(Self.FindComponent('dsDocMaster')); | M := TDataSource(Self.FindComponent('dsDocMaster')); | ||
edCompanyCategory := Self.FindComponent(' | edCompanyCategory := Self.FindComponent('edControlAccount') as TcxDBExtLookupComboBox; | ||
edSearchKey := TcxDBExtLookupComboBox.Create(edCompanyCategory); | edSearchKey := TcxDBExtLookupComboBox.Create(edCompanyCategory); | ||
lbSearchKey := TLabel.Create(edCompanyCategory); | lbSearchKey := TLabel.Create(edCompanyCategory); | ||
Line 759: | Line 773: | ||
with lbSearchKey do begin // Create Label | with lbSearchKey do begin // Create Label | ||
Parent := edCompanyCategory.Parent; | Parent := edCompanyCategory.Parent; | ||
Left := edCompanyCategory.Left + edCompanyCategory.Width + | Left := edCompanyCategory.Left + edCompanyCategory.Width + 150; | ||
Top := edCompanyCategory.Top +3; | Top := edCompanyCategory.Top +3; | ||
Caption := 'Search key :'; | Caption := 'Search key :'; | ||
Line 766: | Line 780: | ||
with edSearchKey do begin // Create Drop List | with edSearchKey do begin // Create Drop List | ||
Parent := edCompanyCategory.Parent; | Parent := edCompanyCategory.Parent; | ||
Left := edCompanyCategory.Left + edCompanyCategory.Width + | Left := edCompanyCategory.Left + edCompanyCategory.Width + 250; | ||
Top := edCompanyCategory.Top; | Top := edCompanyCategory.Top; | ||
Name := 'edSearch'; | Name := 'edSearch'; | ||
Line 817: | Line 831: | ||
D.DataSet.First; | D.DataSet.First; | ||
while not D.DataSet.Eof do begin | while not D.DataSet.Eof do begin | ||
if D.DataSet.FindField('ItemCode').AsString = 'SERVICE' then | if D.DataSet.FindField('ItemCode').AsString = 'SERVICE' then begin | ||
D.DataSet.Delete | D.DataSet.Delete; | ||
else | Continue; | ||
end else | |||
if D.DataSet.FindField('ItemCode').AsString <> 'RTN5Cents' then // To Excluding 5 Cents rounding | if D.DataSet.FindField('ItemCode').AsString <> 'RTN5Cents' then // To Excluding 5 Cents rounding | ||
ODocAmt := ODocAmt + D.DataSet.FindField('Amount').AsFloat; // To Get Total DocAmt before GST | ODocAmt := ODocAmt + D.DataSet.FindField('Amount').AsFloat; // To Get Total DocAmt before GST | ||
Line 1,003: | Line 1,018: | ||
* Auto Click Browse button | * Auto Click Browse button | ||
Last Script Update : | Last Script Update : 20 Apr 2019<br /> | ||
Level : Basic | Level : Basic | ||
Line 1,038: | Line 1,053: | ||
i := i + 1; | i := i + 1; | ||
Self.Caption := Format('%s of %s', [IntToStr(i), IntToStr(G.DataSet.RecordCount)]); | Self.Caption := Format('%s of %s', [IntToStr(i), IntToStr(G.DataSet.RecordCount)]); | ||
BtnBrowse.Click; | Application.ProcessMessages; | ||
BtnBrowse.Click; | |||
BtnEdit.Click; | BtnEdit.Click; | ||
BtnSave.Click; | BtnSave.Click; | ||
Line 1,218: | Line 1,234: | ||
Top := btnMoveDown.Top; | Top := btnMoveDown.Top; | ||
Height := btnMoveDown.Height; | Height := btnMoveDown.Height; | ||
Left := btnMoveDown.Left + btnMoveDown.Width + | Left := btnMoveDown.Left + btnMoveDown.Width + 130; | ||
Width := 120; | Width := 120; | ||
Caption := '&1. Get Excel Data'; | Caption := '&1. Get Excel Data'; | ||
Line 1,310: | Line 1,326: | ||
* Get Data from CSV/TXT & append to detail | * Get Data from CSV/TXT & append to detail | ||
Last Script Update : | Last Script Update : 03 Mar 2018<br /> | ||
Level : Advance | Level : Advance | ||
Line 1,339: | Line 1,355: | ||
S := TStringList.Create; | S := TStringList.Create; | ||
try | try | ||
S.Delimiter | S.Delimiter := ','; | ||
S.DelimitedText := AStr; | S.StrictDelimiter := True; | ||
S.DelimitedText := AStr; | |||
if AIndex < S.Count then Result := Trim(S[AIndex]) | if AIndex < S.Count then Result := Trim(S[AIndex]) | ||
else Result := ''; | else Result := ''; | ||
Line 1,431: | Line 1,448: | ||
| | | | ||
<syntaxhighlight lang="delphi"> | <syntaxhighlight lang="delphi"> | ||
//GL | |||
//- GL Document Listing - Panel2 | |||
//- GL Journal of Transaction Listing - Panel2 | |||
//- GL Transaction Summary - Panel2 | |||
//- GL Ledger - Panel2 | |||
//- GL Receipt and Payment - Panel1 | |||
//Customer | //Customer | ||
//- Customer Document Listing - Panel1, Panel3 | //- Customer Document Listing - Panel1, Panel3 | ||
Line 1,826: | Line 1,850: | ||
Below is Example are doing following actions | Below is Example are doing following actions | ||
* Create 2 buttons at Sales Quotation | * Create 2 buttons at Sales Quotation | ||
:* 1 at Beside | :* 1 at Beside Up Down Button | ||
:* 1 at Below Browse Button | :* 1 at Below Browse Button | ||
Last Script Update : | Last Script Update : 16 Dec 2017<br /> | ||
Level : Basic | Level : Basic | ||
Line 1,849: | Line 1,873: | ||
<syntaxhighlight lang="delphi"> | <syntaxhighlight lang="delphi"> | ||
var C : TComponent; | var C : TComponent; | ||
btnMoveDown : TSpeedButton; | |||
BtnBrowse, btn1, btn2 : TcxButton; | |||
procedure OnClick1(Sender: TObject); | procedure OnClick1(Sender: TObject); | ||
Line 1,865: | Line 1,889: | ||
begin | begin | ||
C | C := Self.FindComponent('frDataSetButton1'); | ||
BtnBrowse := TcxButton(C.FindComponent('btnViewDetail')); | BtnBrowse := TcxButton(C.FindComponent('btnViewDetail')); | ||
btnMoveDown := TSpeedButton(Self.FindComponent('BtnMoveDown')); | |||
btn1 := TcxButton.Create( | btn1 := TcxButton.Create(btnMoveDown); | ||
btn2 := TcxButton.Create( | btn2 := TcxButton.Create(C); | ||
if Assigned( | if Assigned(btnMoveDown) then begin | ||
with btn1 do begin //Create Beside the | with btn1 do begin //Create Beside the Up Down Button | ||
Parent := | Parent := btnMoveDown.Parent; | ||
Top := | Top := btnMoveDown.Top; | ||
Left := | Left := btnMoveDown.Left + btnMoveDown.Width + 120; | ||
Height := | Height := btnMoveDown.Height; | ||
Width := 100; | Width := 100; | ||
Caption := '&1. Button'; | Caption := '&1. Button'; | ||
Line 2,405: | Line 2,429: | ||
<div style="float: right;"> [[#top|[top]]]</div> | <div style="float: right;"> [[#top|[top]]]</div> | ||
===Example 28 - === | ===Example 28 - Approval by User if Document Amount Exceed Limit=== | ||
Below example is to prompt Authorised if the Document Amount Exceed the limit (eg 10000) in Sales Invoice | |||
Last Script Update : 20 Jul 2017<br /> | |||
Level : Advance | |||
: | |||
02. | '''Steps - OnBeforeSave''' | ||
: | :01. Click '''Tools | DIY | SQL Control Center...''' | ||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnBeforeSave''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnBeforeSave Script | |||
|- | |||
{| class="wikitable | | | ||
! | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | <syntaxhighlight lang="delphi"> | ||
var | var FComServer, lBizObj, V : Variant; | ||
M | M : TDataSource; | ||
function ComServer: Variant; | |||
begin | |||
if FComServer = Null then begin | |||
FComServer := CreateOleObject('SQLAcc.BizApp'); | |||
end; | |||
Result := FComServer; | |||
end; | |||
procedure Approved(const lUN, lUPW : string); | |||
var lAPW, lSQL : String; | |||
cdsUsers : TClientDataSet; | |||
begin | begin | ||
FComServer := null; | |||
cdsUsers := TClientDataSet.Create(nil); | |||
lSQL := Format('SELECT UDF_Password FROM SY_USER WHERE Code=%s AND UDF_AllowApproved = 1',[QuotedStr(lUN)]); | |||
try | |||
FComServer := null; | |||
cdsUsers.Data := ComServer.DBManager.Execute(lSQL); | |||
lAPW := cdsUsers.FindField('UDF_Password').AsString; | |||
if (lUPW <> lAPW) or (Trim(lAPW) = '') then begin | |||
MessageDlg('Incorrect Password', mtWarning, [mbOK], 0); | |||
Abort; | |||
end; | |||
finally | |||
lBizObj := null; | |||
FComServer := null; | |||
cdsUsers.Free; | |||
end; | end; | ||
end; | end; | ||
</syntaxhighlight> | |||
procedure InitPWForm; | |||
var fmPassword : TForm; | |||
lbUserName, lbPassword : TcxLabel; | |||
edUserName, edPassword : TEdit; | |||
btnOK : TButton; | |||
begin | |||
fmPassword := TForm.Create(nil); | |||
lbUserName := TcxLabel.Create(fmPassword); | |||
lbPassword := TcxLabel.Create(fmPassword); | |||
edUserName := TEdit.Create(fmPassword); | |||
edPassword := TEdit.Create(fmPassword); | |||
btnOK := TButton.Create(fmPassword); | |||
try | |||
with fmPassword do begin | |||
Parent := nil; | |||
Height := 120; | |||
Width := 280; | |||
Caption := 'Please Enter User Name and Password'; | |||
Color := clWhite; | |||
BorderStyle := bsDialog; | |||
Position := poMainFormCenter; | |||
with lbUserName do begin | |||
Parent := fmPassword; | |||
Left := 10; | |||
Top := 10; | |||
Caption := '&User Name :'; | |||
end; | |||
with edUserName do begin | |||
Parent := fmPassword; | |||
Left := 100; | |||
Top := 10; | |||
Width := 150; | |||
CharCase := ecUpperCase; | |||
end; | |||
with lbPassword do begin | |||
Parent := fmPassword; | |||
Left := 10; | |||
Top := 35; | |||
Caption := '&Password :'; | |||
end; | |||
with edPassword do begin | |||
Parent := fmPassword; | |||
Left := 100; | |||
Top := 35; | |||
Width := 150; | |||
CharCase := ecUpperCase; | |||
PasswordChar := '*'; | |||
end; | |||
with btnOK do begin | |||
Parent := fmPassword; | |||
Top := 60; | |||
Width := 100; | |||
Left := (fmPassword.Width/2) - 50; | |||
Caption := '&OK'; | |||
ModalResult := mrOk; | |||
end; | |||
fmPassword.ScaleBy(fmPassword.Monitor.PixelsPerInch, 96); | |||
if fmPassword.ShowModal = mrOK then | |||
Approved(edUserName.Text, edPassword.Text) else | |||
Approved('',''); | |||
end; | |||
finally | |||
fmPassword.Free; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')); | |||
V := M.DataSet.FindField('DocAmt').AsFloat; | |||
if V >= 10000 then | |||
InitPWForm; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 29 - Add DB Check Box=== | |||
Below example is to create DBCheckBox at Header in Sales Order | |||
Last Script Update : 07 Aug 2017<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Order''' | |||
:03. Right Click the '''Sales Order''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var dsDocMaster : TDataSource; | |||
edFreeDlvery : TcxDBCheckBox; | |||
btnMoveDown : TSpeedButton; | |||
begin | |||
dsDocMaster := TDataSource(Self.FindComponent('dsDocMaster')); | |||
btnMoveDown := TSpeedButton(Self.FindComponent('BtnMoveDown')); | |||
edFreeDlvery := TcxDBCheckBox.Create(self); | |||
if Assigned(btnMoveDown) then begin | |||
with edFreeDlvery do begin | |||
Parent := btnMoveDown .Parent; | |||
Top := btnMoveDown .Top; | |||
Left := btnMoveDown.Left + btnMoveDown.Width + 100; | |||
Width := 100; | |||
Name := 'FreeDlvry'; | |||
Properties.Caption := ' Free Delivery'; | |||
Properties.NullStyle := nssUnchecked; | |||
Properties.ValueChecked := 'T'; | |||
Properties.ValueUnChecked := 'F'; | |||
DataBinding.DataSource := dsDocMaster; | |||
DataBinding.DataField := 'UDF_FreeDlvry'; | |||
end; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 30 - Set Default 14 days delivery date from DocDate=== | |||
Below example is to set Default 14 Days from Document Date in Sales Quotation | |||
Last Script Update : 20 Sep 2017<br /> | |||
Level : Basic | |||
'''Steps - OnGridAfterInsert''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Quotation''' | |||
:03. Right Click the '''Sales Quotation''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnGridAfterInsert''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnGridAferInsert Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var M : TDataSet; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')).Dataset; | |||
Dataset.FindField('DeliveryDate').Value := M.FindField('DocDate').Value +14; | |||
end; | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 31 - Add TcxDBTextEdit === | |||
Below example is to Create new TcxDBTextEdit for UDF_Wastage in Maintain Item | |||
Last Script Update : 21 Dec 2017<br /> | |||
Level : Basic | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Stock''' | |||
:03. Right Click the '''Stock Item''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
Var edWast, edRmk : TcxDBTextEdit; | |||
pnlDock : TWinControl; | |||
dsAccess : TDataSource; | |||
lblWast : TcxLabel; | |||
begin | |||
edRmk := TcxDBTextEdit(Self.FindComponent('edBarcode')); | |||
dsAccess := TDataSource(Self.FindComponent('dsAccess')); | |||
edWast := TcxDBTextEdit.Create(Self); | |||
lblWast := TcxLabel.Create(Self); | |||
with lblWast do begin | |||
Parent := edRmk.Parent; | |||
Left := edRmk.Left - 92; | |||
Top := edRmk.Top + edRmk.Height + 4; | |||
Width := 38; | |||
Height := 17; | |||
Caption := 'Wastage :'; | |||
end; | |||
with edWast do begin | |||
Parent := edRmk.Parent; | |||
Name := 'edWast'; | |||
Left := edRmk.Left; | |||
Top := edRmk.Top + edRmk.Height + 2; | |||
Width := 300; | |||
Height := edRmk.Height; | |||
TabOrder := 20; | |||
DataBinding.DataSource := dsAccess; | |||
DataBinding.DataField := 'UDF_Wastage'; | |||
Properties.Alignment.Horz := taRightJustify; //Align to Right | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 32 - Call Report Object In Script === | |||
Below example is to Create new Button to calculate Margin for each Invoice & update to Header UDF_Margin field | |||
Last Script Update : 23 Nov 2017<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var C : TComponent; | |||
B, btnOK, BtnBrowse : TcxButton; | |||
fmParameter : TForm; | |||
lIVList : TStringList; | |||
lWorkingDate : TDateTime; | |||
lDF , lDT : TcxDateEdit; | |||
P : TDataProcessorProxy; | |||
D : TDataSet; | |||
FComServer, lBizObj, lDocKey, lDocNo, lMainDataSet, V: Variant; | |||
function ComServer: Variant; | |||
begin | |||
if FComServer = Null then begin | |||
FComServer := CreateOleObject('SQLAcc.BizApp'); | |||
end; | |||
Result := FComServer; | |||
end; | |||
function VarToStrDef(const V: Variant; const ADefault: string): string; | |||
begin | |||
if not VarIsNull(V) then | |||
Result := V | |||
else | |||
Result := ADefault; | |||
end; | |||
function VarToStr(const V: Variant): string; | |||
begin | |||
Result := VarToStrDef(V, ''); | |||
end; | |||
function FormatJSonDate(D: TDateTime): String; | |||
var AFormat: string; | |||
begin | |||
AFormat := 'yyyy-mm-dd'; | |||
Result := '"' + FormatDateTime(AFormat, D) + '"'; | |||
end; | |||
procedure SpoolParameter; | |||
begin | |||
P := TDataProcessorProxy.Create('Sales.ProfitLoss.DP'); | |||
P.AsJSONParam := '{' + | |||
' "SelectIV" : true ' + // Boolean (true / false) | |||
', "SelectDO" : false ' + | |||
', "SelectDN" : false ' + | |||
', "SelectCS" : false ' + | |||
', "SelectCN" : false ' + | |||
', "Agent" : [] ' + // List / Array - this mean select ALL | |||
', "Company" : [] ' + | |||
', "Location" : [] ' + // List / Array - this mean select location ---- & Balakong | |||
', "CompanyCategory" : [] ' + | |||
', "HasCategory" : false ' + | |||
', "WithSalesTax" : false ' + | |||
', "StockGroup" : [] ' + | |||
', "DateFrom" : ' + FormatJSonDate(lDF.Date) + // Date format is yyyy-mm-dd | |||
', "DateTo" : ' + FormatJSonDate(lDT.Date) + | |||
', "Doc_IV" : [] ' + | |||
', "Doc_DO" : [] ' + | |||
', "Doc_DN" : [] ' + | |||
', "Doc_CS" : [] ' + | |||
', "Doc_CN" : [] ' + | |||
', "Category" : [] ' + | |||
', "ItemProject" : [] ' + | |||
', "DocProject" : [] ' + | |||
', "SelectDate" : true ' + | |||
', "CategoryTpl" : "" ' + //String | |||
', "Item" : [] ' + | |||
', "Area" : [] ' + | |||
', "UseRefCost" : false ' + | |||
', "Batch" : [] ' + | |||
'}'; | |||
P.Execute; | |||
end; | |||
procedure GetIVList; | |||
begin | |||
lIVList := TStringList.Create; | |||
lIVList.Duplicates := dupIgnore; | |||
lIVList.Sorted := True; | |||
D.First; | |||
while not D.Eof do begin | |||
lIVList.Append(D.FindField('DocNo').AsString); | |||
D.Next; | |||
end; | |||
end; | |||
procedure OnClickApply(Sender: TObject); | |||
var i, j : integer; | |||
begin | |||
SpoolParameter; | |||
D := P.GetDataSetByName('Main'); | |||
GetIVList; | |||
FComServer := null; | |||
lBizObj := null; | |||
lBizObj := ComServer.BizObjects.Find('SL_IV'); | |||
lMainDataSet := lBizObj.DataSets.Find('MainDataSet'); | |||
i := 0; | |||
for j := 0 to lIVList.Count -1 do begin | |||
i := i + 1; | |||
V := Format('%d of %d',[i, lIVList.Count]); | |||
btnOK.Caption := V; | |||
lDocNo := lIVList[j]; | |||
lDocKey := lBizObj.FindKeyByRef('DocNo', lDocNo); | |||
lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey); | |||
with D do begin | |||
Filter := 'DocNo=' + QuotedStr(lIVList[j]); | |||
Filtered := True; | |||
end; | |||
if not VarIsNull(lDocKey) then begin | |||
lBizObj.Open; | |||
lBizObj.Edit; | |||
lMainDataSet.FindField('UDF_Margin').AsFloat := D.FindField('DocMargin').AsFloat; | |||
lBizObj.Save; | |||
D.Filtered := False; | |||
end; | |||
end; | |||
lIVList.Free; | |||
if Assigned(P) then | |||
P.Free; | |||
FComServer := null; | |||
lBizObj := null; | |||
btnOK.Caption := '&Apply'; | |||
MessageDlg('Record(s) successfully Updated', mtInformation, [mbOk], 0); | |||
fmParameter.Close; | |||
end; | |||
procedure InitForm; | |||
var lbDF, lbDT : TcxLabel; | |||
begin | |||
lWorkingDate := CurrentWorkingDate; | |||
fmParameter := TForm.Create(nil); | |||
lDF := TcxDateEdit.Create(fmParameter); | |||
lDT := TcxDateEdit.Create(fmParameter); | |||
btnOK := TcxButton.Create(fmParameter); | |||
lbDF := TcxLabel.Create(fmParameter); | |||
lbDT := TcxLabel.Create(fmParameter); | |||
try | |||
with fmParameter do begin | |||
Parent := nil; | |||
Height := 100; | |||
Width := 300; | |||
Caption := 'Date range..'; | |||
Color := clWhite; | |||
BorderStyle := bsDialog; | |||
Position := poMainFormCenter; | |||
with lbDF do begin | |||
Parent := fmParameter; | |||
Left := 5; | |||
Top := 10; | |||
Caption := 'Date :' | |||
end; | |||
with lDF do begin | |||
Parent := fmParameter; | |||
Top := 10; | |||
Left := 40; | |||
Width := 100; | |||
Date := StartOfAMonth(YearOf(lWorkingDate), MonthOf(lWorkingDate)); | |||
end; | |||
with lbDT do begin | |||
Parent := fmParameter; | |||
Left := 145; | |||
Top := 10; | |||
Caption := ' To ' | |||
end; | |||
with lDT do begin | |||
Parent := fmParameter; | |||
Top := 10; | |||
Left := 180; | |||
Width := 100; | |||
Date := Trunc(EndOfAMonth(YearOf(lWorkingDate), MonthOf(lWorkingDate))); | |||
end; | |||
with btnOK do begin | |||
Parent := fmParameter; | |||
Top := 35; | |||
Width := 100; | |||
Left := (fmParameter.Width/2) - 50; | |||
Caption := '&Apply'; | |||
OnClick := @OnClickApply; | |||
end; | |||
end; | |||
fmParameter.ScaleBy(fmParameter.Monitor.PixelsPerInch, 96); | |||
fmParameter.ShowModal; | |||
finally | |||
fmParameter.Free; | |||
end; | |||
end; | |||
procedure OnClickForm(Sender: TObject); | |||
begin | |||
InitForm; | |||
end; | |||
begin | |||
C := Self.FindComponent('frDataSetButton1'); | |||
BtnBrowse := TcxButton(C.FindComponent('btnViewDetail')); | |||
if Assigned(C) then | |||
B := TcxButton.Create(Self); | |||
B.Parent := TwinControl(c); | |||
B.width := BtnBrowse.Width; | |||
B.Top := BtnBrowse.Top + BtnBrowse.Height + 5; | |||
B.Left := BtnBrowse.Left; | |||
B.Height := BtnBrowse.Height; | |||
B.Caption := 'Calc Margin'; | |||
B.OnClick := @OnClickForm; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 33 - Set Discount to Empty for next line=== | |||
Below is Example will automatic remove the Discount field value on insert next item line. | |||
Last Script Update : 27 Nov 2017<br /> | |||
Level : Basic | |||
'''Steps - OnGridAfterInsert''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnGridAfterInsert''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnGridAfterInsert Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
begin | |||
Dataset.FindField('Disc').AsString := ''; | |||
end; | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 34 - Prompt Dialog for Discount=== | |||
Below is Example are doing following actions | |||
* Auto Append ItemCode '''DISC''' | |||
* Do Calculation for ItemCode '''DISC''' UnitPrice := Total Doc Amount * Rate Enter | |||
Last Script Update : 29 Nov 2017<br /> | |||
Level : Basic | |||
'''Steps - OnBeforeSave''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnBeforeSave''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnBeforeSave Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var M, D : TDataSource; | |||
function GetDiscountedValue(AValue: Variant; Discount: string): Variant; | |||
var | |||
lStrLst: TStringList; | |||
S: string; | |||
I: Integer; | |||
begin | |||
Result := Null; | |||
lStrLst := TStringList.Create; | |||
try | |||
try | |||
lStrLst.Delimiter := '&'; | |||
lStrLst.DelimitedText := Trim(StringReplace(Trim(Discount), '+', '&', [rfReplaceAll])); | |||
for I := 0 to lStrLst.Count - 1 do | |||
begin | |||
S := Trim(lStrLst.Strings[I]); | |||
if S[Length(S)] = '%' then | |||
begin | |||
S := Trim(Copy(S, 1, Length(S) - 1)); | |||
AValue := AValue * ((StrToFloat(S)) / 100); | |||
end | |||
else | |||
AValue := StrToFloat(S); | |||
end; | |||
Result := AValue*-1; | |||
except | |||
RaiseException(ExceptionType, 'Discount formatting error '); | |||
end; | |||
finally | |||
lStrLst.Free; | |||
end; | |||
end; | |||
procedure CalcDisc(const lRate:String); | |||
var lDocAmt : Variant; | |||
begin | |||
lDocAmt := M.DataSet.FindField('DocAmt').AsFloat; | |||
with D.DataSet do begin | |||
Edit; | |||
Append; | |||
FindField('ItemCode').AsString := 'DISC'; | |||
FindField('Description').AsString := FindField('Description').AsString + ' -' + lRate+'%'; | |||
FindField('Qty').AsFloat := 1; | |||
FindField('UnitPrice').AsFloat := GetDiscountedValue(lDocAmt, lRate+'%'); | |||
Post; | |||
end; | |||
end; | |||
procedure InitPWForm; | |||
var fmPassword : TForm; | |||
lbRate : TcxLabel; | |||
edRate : TcxTextEdit; | |||
btnOK : TButton; | |||
begin | |||
fmPassword := TForm.Create(nil); | |||
lbRate := TcxLabel.Create(fmPassword); | |||
edRate := TcxTextEdit.Create(fmPassword); | |||
btnOK := TButton.Create(fmPassword); | |||
try | |||
with fmPassword do begin | |||
Parent := nil; | |||
Height := 100; | |||
Width := 280; | |||
Caption := 'Enter the Discount Rate (%)'; | |||
Color := clWhite; | |||
BorderStyle := bsDialog; | |||
Position := poMainFormCenter; | |||
with lbRate do begin | |||
Parent := fmPassword; | |||
Left := 10; | |||
Top := 10; | |||
Caption := '&Rate :'; | |||
end; | |||
with edRate do begin | |||
Parent := fmPassword; | |||
Left := 100; | |||
Top := 10; | |||
Width := 150; | |||
end; | |||
with btnOK do begin | |||
Parent := fmPassword; | |||
Top := 38; | |||
Width := 100; | |||
Left := (fmPassword.Width/2) - 50; | |||
Caption := '&OK'; | |||
ModalResult := mrOk; | |||
end; | |||
fmPassword.ScaleBy(fmPassword.Monitor.PixelsPerInch, 96); | |||
if fmPassword.ShowModal = mrOK then | |||
CalcDisc(edRate.Text); | |||
end; | |||
finally | |||
fmPassword.Free; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')); | |||
D := TDataSource(Self.FindComponent('dsDocDetail')); | |||
InitPWForm; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 35 - Create New Grid Tab on Existing Grid=== | |||
Below is Example are create new Tab in Existing Grid in Customer Due Listing<br /> | |||
Last Script Update : 03 Jan 2018<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Customer Due Document''' | |||
:03. Right Click the '''Customer Due Document''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var btnCalc, btnApply : TcxButton; | |||
M, dsGrid : TDatasource; | |||
FcxGrid : TcxGrid; | |||
gvGrid : TcxGridDBTableView; | |||
cdsMain : TClientDataSet; | |||
lDisplayFormat : String; | |||
procedure Setup; | |||
begin | |||
dsGrid := TDataSource.Create(nil); | |||
cdsMain := TClientDataSet.Create(nil); | |||
end; | |||
procedure FreeCmpt(lComponent :TObject); | |||
begin | |||
if Assigned(lComponent) then | |||
lComponent.Free; | |||
end; | |||
procedure TearDown; | |||
begin | |||
FreeCmpt(dsGrid); | |||
FreeCmpt(cdsMain); | |||
end; | |||
procedure SetNumericDisplayFormat(AClientDataSet: TClientDataSet); | |||
var f : TFMTBCDField; | |||
f1 : TFloatField; | |||
i : Integer; | |||
begin | |||
for i := 0 to AClientDataSet.FieldCount - 1 do begin | |||
if AClientDataSet.FieldDefs.Items[i].DataType = ftFMTBcd then begin | |||
f := TFMTBCDField(AClientDataSet.Fields.Fields[i]); | |||
if not (f = nil) then f.DisplayFormat := lDisplayFormat; | |||
end; | |||
if AClientDataSet.FieldDefs.Items[i].DataType = ftFloat then begin | |||
f1 := TFloatField(AClientDataSet.Fields.Fields[i]); | |||
if not (f1 = nil) then f1.DisplayFormat := lDisplayFormat; | |||
end; | |||
end; | |||
end; | |||
procedure PrepareNewTab; | |||
var i : integer; | |||
begin | |||
FcxGrid.RootLevelOptions.DetailTabsPosition := dtpTop; | |||
if FcxGrid.Levels.Count > 1 then begin | |||
for i := FcxGrid.Levels.Count - 1 downto 1 do begin | |||
FcxGrid.Levels[i].GridView.Free; | |||
FcxGrid.Levels[i].Free; | |||
end; | |||
Self.Refresh; | |||
end; | |||
gvGrid := CreateTcxGridDBTableView(FcxGrid); | |||
with FcxGrid.Levels.Add do begin | |||
Caption := 'Calc'; | |||
GridView := TcxCustomGridView(gvGrid); | |||
Active := True; | |||
end; | |||
with gvGrid do begin | |||
Name := 'Restricted_1'; | |||
OptionsCustomize.ColumnFiltering := False; | |||
OptionsView.ColumnAutoWidth := True; | |||
OptionsView.Footer := True; | |||
OptionsView.GroupByBox := False; | |||
OptionsBehavior.IncSearch := True; | |||
DataController.DataSource := dsGrid; | |||
OptionsData.Editing := False; | |||
end; | |||
end; | |||
procedure CreateXMLTable; | |||
begin | |||
FreeCmpt(cdsMain); | |||
cdsMain := TClientDataSet.Create(nil); | |||
cdsMain.FieldDefs.Assign(M.DataSet.FieldDefs); | |||
cdsMain.CreateDataSet; | |||
cdsMain.IndexFieldNames := 'Code';// Sort By Code | |||
dsGrid.DataSet := cdsMain; | |||
gvGrid.DataController.DataSource := dsGrid; | |||
gvGrid.DataController.CreateAllItems(False);// Create cxGridColumn | |||
end; | |||
procedure TuneGridColumn; | |||
var B : Boolean; | |||
begin | |||
B := False; | |||
with gvGrid do begin | |||
//Hide Columns | |||
//for i := 0 to ColumnCount -1 do | |||
// Columns[i].Visible := False; // To 1 shot hide all fields | |||
GetColumnByFieldName('Dockey').Visible := B; | |||
GetColumnByFieldName('DocNoEx').Visible := B; | |||
GetColumnByFieldName('PostDate').Visible := B; | |||
GetColumnByFieldName('Agent').Visible := B; | |||
GetColumnByFieldName('Journal').Visible := B; | |||
GetColumnByFieldName('CurrencyCode').Visible := B; | |||
GetColumnByFieldName('CurrencyRate').Visible := B; | |||
GetColumnByFieldName('LocalDocAmt').Visible := B; | |||
GetColumnByFieldName('Cancelled').Visible := B; | |||
GetColumnByFieldName('Project').Visible := B; | |||
GetColumnByFieldName('Area').Visible := B; | |||
GetColumnByFieldName('DocType').Visible := B; | |||
GetColumnByFieldName('PaymentAmt').Visible := B; | |||
GetColumnByFieldName('LocalPaymentAmt').Visible := B; | |||
GetColumnByFieldName('CNAmt').Visible := B; | |||
GetColumnByFieldName('LocalCNAmt').Visible := B; | |||
GetColumnByFieldName('CTAmt').Visible := B; | |||
GetColumnByFieldName('LocalCTAmt').Visible := B; | |||
GetColumnByFieldName('GainLoss').Visible := B; | |||
GetColumnByFieldName('CompanyCategory').Visible := B; | |||
GetColumnByFieldName('Description').Visible := B; | |||
GetColumnByFieldName('Code').Visible := B; | |||
//Reposition Columns | |||
GetColumnByFieldName('DocNo').Index := 0; | |||
GetColumnByFieldName('DocDate').Index := 1; | |||
GetColumnByFieldName('DueDate').Index := 2; | |||
GetColumnByFieldName('CompanyName').Index := 3; | |||
GetColumnByFieldName('Terms').Index := 4; | |||
GetColumnByFieldName('DocAmt').Index := 5; | |||
GetColumnByFieldName('Outstanding').Index := 6; | |||
GetColumnByFieldName('LocalOutstanding').Index := 7; | |||
GetColumnByFieldName('Age').Index := 8; | |||
//Rename Columns | |||
GetColumnByFieldName('DocNo').Caption := 'Doc No'; | |||
GetColumnByFieldName('DocDate').Caption := 'Doc Date'; | |||
GetColumnByFieldName('DueDate').Caption := 'Due Date'; | |||
GetColumnByFieldName('CompanyName').Caption := 'Company Name'; | |||
end; | |||
with gvGrid.DataController.Summary do begin | |||
BeginUpdate; | |||
try | |||
with TcxGridDBTableSummaryItem(FooterSummaryItems.Add) do begin | |||
Column := gvGrid.GetColumnByFieldName('DocNo'); | |||
Position := spFooter; | |||
Kind := skCount; | |||
Format := 'Count = #'; | |||
end; | |||
with TcxGridDBTableSummaryItem(FooterSummaryItems.Add) do begin | |||
Column := gvGrid.GetColumnByFieldName('DocAmt'); | |||
Position := spFooter; | |||
Kind := skSum; | |||
Format := lDisplayFormat; | |||
end; | |||
with TcxGridDBTableSummaryItem(FooterSummaryItems.Add) do begin | |||
Column := gvGrid.GetColumnByFieldName('Outstanding'); | |||
Position := spFooter; | |||
Kind := skSum; | |||
Format := lDisplayFormat; | |||
end; | |||
with TcxGridDBTableSummaryItem(FooterSummaryItems.Add) do begin | |||
Column := gvGrid.GetColumnByFieldName('LocalOutstanding'); | |||
Position := spFooter; | |||
Kind := skSum; | |||
Format := lDisplayFormat; | |||
end; | |||
finally | |||
EndUpdate; | |||
end; | |||
end; | |||
end; | |||
procedure PrepareData; | |||
var i : integer; | |||
begin | |||
M.Dataset.DisableControls; | |||
cdsMain.DisableControls; | |||
try | |||
M.Dataset.First; | |||
while not M.Dataset.EOF do begin | |||
cdsMain.Append; | |||
for i:=0 to M.Dataset.FieldDefs.Count-1 do | |||
cdsMain.FindField(M.Dataset.FieldDefs.Items[i].Name).Value := M.Dataset.FindField(M.Dataset.FieldDefs.Items[i].Name).Value; | |||
cdsMain.Post; | |||
M.Dataset.Next; | |||
end; | |||
finally | |||
SetNumericDisplayFormat(cdsMain); //Set DisplayFormat | |||
M.Dataset.EnableControls; | |||
cdsMain.EnableControls; | |||
cdsMain.First; | |||
gvGrid.ApplyBestFit(nil, False, False); | |||
end; | |||
end; | |||
procedure OnGenClick(Sender: TObject); | |||
var s : string; | |||
begin | |||
s := self.Caption; | |||
lDisplayFormat := '#,0.00;-#,0.00;-'; | |||
try | |||
self.Caption := 'Get Raw Information...'; | |||
btnApply.Click; | |||
self.Caption := 'Prepare Tab...'; | |||
PrepareNewTab; | |||
self.Caption := 'Prepare XML Table...'; | |||
CreateXMLTable; | |||
self.Caption := 'Grid Tuning...'; | |||
TuneGridColumn; | |||
self.Caption := 'Preparing Data...'; | |||
PrepareData; | |||
finally | |||
self.Caption := s; | |||
end; | |||
end; | |||
begin | |||
btnApply := Tcxbutton(Self.FindComponent('btnApply')); | |||
FcxGrid := TcxGrid(Self.FindComponent('FcxGrid')); | |||
M := TDatasource(Self.FindComponent('dsMain')); | |||
btnCalc := TcxButton.Create(Self); | |||
with btnCalc do begin | |||
Parent := btnApply.Parent; | |||
Top := btnApply.Top; | |||
Left := btnApply.Left + btnApply.Width + 5; | |||
Width := btnApply.Width + 2; | |||
Caption := '&1. Generate'; | |||
ShowHint := True; | |||
Hint := 'Generate Overdue List'; | |||
OnClick := @OnGenClick; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 36 - How to Detect what is the Current Doc Type in Document Listing?=== | |||
Last Script Update : 10 Aug 2018<br /> | |||
Level : Basic | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Document Listing''' | |||
:03. Right Click the '''Sales Document Listing''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var edDocumentType : TcxComboBox; | |||
procedure edDocumentTypeChange(Sender: TObject); | |||
var s : string; | |||
begin | |||
s := 'Now selected Doc type is ' + edDocumentType.EditValue; | |||
MessageDlg(S, mtInformation, [mbOk], 0); | |||
end; | |||
begin | |||
edDocumentType := TcxComboBox(Self.FindComponent('edDocumentType')); | |||
edDocumentType.Properties.OnEditValueChanged := @edDocumentTypeChange; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 37 - Simple Copy From Dataset to New Doc === | |||
Below is Example to Copy Quotation Information to Sales Invoice<br /> | |||
Last Script Update : 08 Sep 2018<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Quotation''' | |||
:03. Right Click the '''Sales Quotation''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var FComServer, lBizObj, lMainDataSet, lDocDetail : Variant; | |||
btnMoveDown : TSpeedButton; | |||
btnCopy : TcxButton; | |||
M, D : TDataSet; | |||
cdsMaster, cdsDetail : TClientDataSet; | |||
function ComServer: Variant; | |||
begin | |||
if FComServer = Null then begin | |||
FComServer := CreateOleObject('SQLAcc.BizApp'); | |||
end; | |||
Result := FComServer; | |||
end; | |||
procedure Setup; | |||
begin | |||
cdsMaster := TClientDataSet.Create(nil); | |||
cdsDetail := TClientDataSet.Create(nil); | |||
end; | |||
procedure FreeCmpt(lComponent :TObject); | |||
begin | |||
if Assigned(lComponent) then | |||
lComponent.Free; | |||
end; | |||
procedure TearDown; | |||
begin | |||
FreeCmpt(cdsMaster); | |||
FreeCmpt(cdsDetail); | |||
end; | |||
procedure CreateXMLTable; | |||
begin | |||
with cdsMaster.FieldDefs do | |||
begin | |||
Add('FName', ftString, 100, False); | |||
end; | |||
with cdsDetail.FieldDefs do | |||
begin | |||
Add('FName', ftString, 100, False); | |||
end; | |||
cdsMaster.CreateDataSet; | |||
cdsDetail.CreateDataSet; | |||
end; | |||
procedure AddField(const lTbl, lFld:String); | |||
begin | |||
if lTbl = 'M' then | |||
with cdsMaster do begin | |||
Append; | |||
FieldValues['FName'] := lFld | |||
Post; | |||
end else | |||
with cdsDetail do begin | |||
Append; | |||
FieldValues['FName'] := lFld; | |||
Post; | |||
end; | |||
end; | |||
procedure PostToAcc; | |||
var lFName : string; | |||
begin | |||
lBizObj.New; | |||
lMainDataSet.FindField('DOCKEY').Value := -1; | |||
cdsMaster.First; | |||
while not cdsMaster.Eof do begin | |||
lFName := cdsMaster.FieldValues['FName']; | |||
lMainDataSet.FindField(lFName).Value := M.FindField(lFName).Value; | |||
cdsMaster.Next; | |||
end; | |||
lMainDataSet.Post; | |||
D.First; | |||
while not D.Eof do begin | |||
lDocDetail.Append; | |||
lDocDetail.FindField('DtlKey').Value := -1; | |||
lDocDetail.FindField('DocKey').Value := -1; | |||
cdsDetail.First; | |||
while not cdsDetail.Eof do begin | |||
lFName := cdsDetail.FieldValues['FName']; | |||
lDocDetail.FindField(lFName).Value := D.FindField(lFName).Value; | |||
cdsDetail.Next; | |||
end; | |||
lDocDetail.Post; | |||
D.Next; | |||
end; | |||
lBizObj.Save; | |||
lBizObj.Close; | |||
end; | |||
procedure OnClick1(Sender: TObject); | |||
begin | |||
FComServer := null; | |||
lBizObj := null; | |||
lBizObj := ComServer.BizObjects.Find('SL_IV'); | |||
lMainDataSet := lBizObj.DataSets.Find('MainDataSet'); | |||
lDocDetail := lBizObj.DataSets.Find('cdsDocDetail'); | |||
try | |||
PostToAcc; | |||
MessageDlg('Posting Done', mtInformation, [mbOk], 0); | |||
finally | |||
lMainDataSet := null; | |||
lDocDetail := null; | |||
lBizObj := null; | |||
FComServer := null; | |||
end; | |||
end; | |||
begin | |||
btnMoveDown := TSpeedButton(Self.FindComponent('BtnMoveDown')); | |||
M := TDataSource(Self.FindComponent('dsDocMaster')).Dataset; | |||
D := TDataSource(Self.FindComponent('dsDocDetail')).Dataset; | |||
btnCopy := TcxButton.Create(btnMoveDown); | |||
if Assigned(btnMoveDown) then begin | |||
with btnCopy do begin //Create Beside the Up Down Button | |||
Parent := btnMoveDown.Parent; | |||
Top := btnMoveDown.Top; | |||
Left := btnMoveDown.Left + btnMoveDown.Width + 120; | |||
Height := btnMoveDown.Height; | |||
Width := 100; | |||
Caption := '&1. Copy To IV'; | |||
OnClick := @OnClick1; | |||
ShowHint := True; | |||
Hint := 'Copy To IV'; | |||
end; | |||
end; | |||
CreateXMLTable; | |||
//Add Field Master Table | |||
AddField('M', 'Code'); | |||
AddField('M', 'DocNoEx'); | |||
//AddField('M', 'CompanyName'); | |||
//AddField('M', 'Address1'); | |||
//AddField('M', 'Address2'); | |||
//AddField('M', 'Address3'); | |||
//AddField('M', 'Address4'); | |||
//AddField('M', 'Phone1'); | |||
//AddField('M', 'Fax1'); | |||
//AddField('M', 'Attention'); | |||
//AddField('M', 'Area'); | |||
//AddField('M', 'Agent'); | |||
AddField('M', 'Project'); | |||
//AddField('M', 'Terms'); | |||
//AddField('M', 'CurrencyRate'); | |||
AddField('M', 'Description'); | |||
//AddField('M', 'D_Amount'); | |||
AddField('M', 'Validity'); | |||
AddField('M', 'DeliveryTerm'); | |||
AddField('M', 'CC'); | |||
AddField('M', 'DocRef1'); | |||
AddField('M', 'DocRef2'); | |||
AddField('M', 'DocRef3'); | |||
AddField('M', 'DocRef4'); | |||
AddField('M', 'BranchName'); | |||
//AddField('M', 'DAddress1'); | |||
//AddField('M', 'DAddress2'); | |||
//AddField('M', 'DAddress3'); | |||
//AddField('M', 'DAddress4'); | |||
//AddField('M', 'DPhone1'); | |||
//AddField('M', 'DFax1'); | |||
//Add Field Detail Table | |||
AddField('D', 'Number'); | |||
AddField('D', 'ItemCode'); | |||
AddField('D', 'Description'); | |||
AddField('D', 'Description2'); | |||
AddField('D', 'Description3'); | |||
AddField('D', 'Remark1'); | |||
AddField('D', 'Remark2'); | |||
AddField('D', 'Location'); | |||
AddField('D', 'Project'); | |||
AddField('D', 'Qty'); | |||
AddField('D', 'UOM'); | |||
AddField('D', 'UnitPrice'); | |||
AddField('D', 'Disc'); | |||
AddField('D', 'Tax'); | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 38 - Create New Column on Existing Grid === | |||
Below is Example to Add UDF_Margin in the Sales Document Listing<br /> | |||
This only work if in Report Designer in Main Pipeline/Table had the field(s)<br /> | |||
Last Script Update : 19 Feb 2019<br /> | |||
Level : Basic | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Document Listing''' | |||
:03. Right Click the '''Sales Document Listing''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var C: TcxGridDBTableView; | |||
begin | |||
C := TcxGridDBTableView(Self.FindComponent('gvMaster')); | |||
if C.GetColumnByFieldName('UDF_Margin') = nil then begin | |||
with C.CreateColumn do begin | |||
DataBinding.FieldName := 'UDF_Margin'; | |||
Caption := 'Margin'; | |||
end; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 39 - Auto Click Apply button and Change the report Grid Data=== | |||
Below Example is to Change Header & Detail Description field in Sales Document Listing | |||
Last Script Update : 21 Mar 2019<br /> | |||
Level : Basic | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Document Listing''' | |||
:03. Right Click the '''Sales Document Listing''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var btnApply, btnCalc : Tcxbutton; | |||
M, D : TDataset; | |||
procedure OnGenerate(Sender: TObject); | |||
var lMDesc, lDDesc, lDocNo : String; | |||
begin | |||
btnApply.Click; //Auto Click Apply button | |||
M := TDataSource(Self.FindComponent('dsMasterTrans')).Dataset; | |||
D := TDataSource(Self.FindComponent('dsDetail')).Dataset; | |||
M.DisableControls; | |||
D.DisableControls; | |||
try | |||
M.First; | |||
while not M.Eof do begin | |||
lDocNo := M.FindField('DocNo').AsString; | |||
lMDesc := M.FindField('Description').AsString + | |||
'- Hello Change Master Description'; | |||
M.Edit; | |||
M.FindField('Description').AsString := lMDesc; | |||
M.Post; | |||
M.Next; | |||
end; | |||
D.First; | |||
while not D.Eof do begin | |||
lDDesc := D.FindField('Description').AsString + | |||
'- Hello Change Detail Description'; | |||
D.Edit; | |||
D.FindField('Description').AsString := lDDesc; | |||
D.Post; | |||
D.Next; | |||
end; | |||
MessageDlg('Done', mtInformation, [mbOk], 0); | |||
finally | |||
M.EnableControls; | |||
D.EnableControls; | |||
end; | |||
end; | |||
begin | |||
btnApply := Tcxbutton(Self.FindComponent('btnApply')); | |||
btnCalc := TcxButton.Create(btnApply); | |||
with btnCalc do begin | |||
Parent := btnApply.Parent; | |||
Top := btnApply.Top; | |||
Left := btnApply.Left + btnApply.Width + 2; | |||
Width := 100; | |||
Caption := '&1. Generate'; | |||
OnClick := @OnGenerate; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 40 - Update DocNo To other Document=== | |||
Below Example is to Update UDF_ORNo in Sales Invoice for Knock-off Payment from Customer Payment | |||
Last Script Update : 03 Jul 2019<br /> | |||
Level : Advance | |||
'''Steps - OnAfterSave''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Customer Payment''' | |||
:03. Right Click the '''Customer Payment''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnAfterSave''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnAfterSave Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var M, D : TDataSet; | |||
FComServer, lBizObj : Variant; | |||
function ComServer: Variant; | |||
begin | |||
if FComServer = Null then begin | |||
FComServer := CreateOleObject('SQLAcc.BizApp'); | |||
end; | |||
Result := FComServer; | |||
end; | |||
function VarToStrDef(const V: Variant; const ADefault: string): string; | |||
begin | |||
if not VarIsNull(V) then | |||
Result := V | |||
else | |||
Result := ADefault; | |||
end; | |||
function VarToStr(const V: Variant): string; | |||
begin | |||
Result := VarToStrDef(V, ''); | |||
end; | |||
procedure UpdateIV(const lDocNo:String); | |||
var lMainDataSet, lDocKey : Variant; | |||
begin | |||
FComServer := null; | |||
lBizObj := null; | |||
try | |||
lBizObj := ComServer.BizObjects.Find('SL_IV'); | |||
lMainDataSet := lBizObj.DataSets.Find('MainDataSet'); | |||
lDocKey := lBizObj.FindKeyByRef('DocNo', lDocNo); | |||
lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey); | |||
if not VarIsNull(lDocKey) then begin | |||
lBizObj.Open; | |||
lBizObj.Edit; | |||
lMainDataSet.FindField('UDF_ORNo').Value := M.FindField('DocNo').Value; | |||
lBizObj.Save; | |||
lBizObj.Close; | |||
end; | |||
finally | |||
lBizObj := null; | |||
FComServer := null; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')).Dataset; | |||
D := TDataSource(Self.FindComponent('dsaKnockOff')).Dataset; | |||
D.First; | |||
while not D.Eof do begin | |||
if (D.FindField('Outstanding').AsFloat = 0) and | |||
(D.FindField('KnockOff').AsString = 'T') then | |||
UpdateIV(D.FindField('DocNo').AsString); | |||
D.Next; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 41 - How to Reset the Serial Number When update Location Field?=== | |||
Below Example is to Set Back the Serial Number List when Location change/Updated | |||
Last Script Update : 19 Oct 2020<br /> | |||
Level : Advance | |||
'''Steps - OnBeforeSave''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnBeforeSave''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnBeforeSave Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var M, D, SN : TDataSet; | |||
lSN : TStringList; | |||
procedure GetSN; | |||
begin | |||
SN.First; | |||
while not SN.Eof do begin | |||
lSN.Append(SN.FindField('SerialNumber').AsString); | |||
SN.Next; | |||
end; | |||
end; | |||
procedure SetSN; | |||
var i : integer; | |||
begin | |||
for i := 0 to lSN.Count -1 do begin | |||
SN.Append; | |||
SN.FindField('SerialNumber').AsString := lSN[i]; | |||
SN.Post; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')).DataSet; | |||
D := TDataSource(Self.FindComponent('dsDocDetail')).Dataset; | |||
SN := TDataSource(Self.FindComponent('dsSerialNumber')).Dataset; | |||
lSN := TStringList.Create; | |||
D.First; | |||
try | |||
while not D.EOF do begin | |||
lSN.Clear; | |||
if D.FindField('Location').AsString <> 'KL' then begin | |||
GetSN; | |||
D.Edit; | |||
D.FindField('Location').AsString := 'KL'; //Location Field is change/Updated | |||
SetSN; | |||
end; | |||
D.Next; | |||
end; | |||
finally | |||
lSN.Free; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 42 - How to find component in Advance Form?=== | |||
Below Example is to change the label in Advance Form | |||
Last Script Update : 23 Jan 2020<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
// Create Advance Form & Rename it to fmCalc (under Object Inspector) | |||
// Drop 1 label & Rename it to lbBankCode (under Object Inspector) | |||
// Load it OnOpen script | |||
var C : TForm; | |||
edAccNo : TLabel; | |||
begin | |||
C := TForm(Self.FindComponent('fmCalc')); | |||
edAccNo := TLabel(C.FindComponent('lbBankCode')); | |||
if Assigned(edAccNo) then | |||
edAccNo.Caption := 'Fairy'; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 43 - DropDown List from Maintenance List=== | |||
Below is Example are doing following actions | |||
* Create Label | |||
* Create a drop down list at Sales Invoice for UDF_Agent2 | |||
Last Script Update : 07 Apr 2020<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var FComServer : Variant; | |||
M : TDataSource; | |||
lbAgent : TLabel; | |||
cdsAgent : TClientDataSet; | |||
grGrid1 : TcxGrid; | |||
dsAgent : TDataSource; | |||
gvDocDetail, gvAgent : TcxGridDBTableView; | |||
btnProfit : TcxButton; | |||
cxAgent : TcxDBExtLookupComboBox; | |||
function ComServer: Variant; | |||
begin | |||
if FComServer = Null then begin | |||
FComServer := CreateOleObject('SQLAcc.BizApp'); | |||
end; | |||
Result := FComServer; | |||
end; | |||
procedure Setup; | |||
begin | |||
cdsAgent := TClientDataSet.Create(nil); | |||
end; | |||
procedure FreeCmpt(lComponent :TObject); | |||
begin | |||
if Assigned(lComponent) then | |||
lComponent.Free; | |||
end; | |||
procedure TearDown; | |||
begin | |||
FreeCmpt(cdsAgent); | |||
end; | |||
procedure PrepareXML; | |||
var lSQL : String; | |||
begin | |||
FComServer := null; | |||
try | |||
lSQL := 'SELECT Code, Description FROM Agent ' + | |||
'WHERE ISActive=''T'' '; | |||
cdsAgent.Data := ComServer.DBManager.Execute(lSQL); | |||
finally | |||
FComServer := null; | |||
end; | |||
end; | |||
procedure CreateTable; | |||
begin | |||
grGrid1 := TcxGrid.Create(nil); | |||
gvAgent := TcxGridDBTableView.Create(grGrid1); | |||
dsAgent := TDataSource.Create(gvDocDetail); | |||
with grGrid1 do begin | |||
Parent := nil; | |||
Visible := False; | |||
end; | |||
with grGrid1.Levels.Add do begin | |||
Caption := 'AgentView'; | |||
GridView := TcxCustomGridView(gvAgent); | |||
end; | |||
dsAgent.DataSet := cdsAgent; | |||
with gvAgent.CreateColumn do begin | |||
Caption := 'Code'; | |||
DataBinding.FieldName := 'Code'; | |||
HeaderAlignmentHorz := taCenter; | |||
Width := 50; | |||
Options.Editing := False; | |||
end; | |||
with gvAgent.CreateColumn do begin | |||
Caption := 'Description'; | |||
DataBinding.FieldName := 'Description'; | |||
HeaderAlignmentHorz := taCenter; | |||
Width := 100; | |||
Options.Editing := False; | |||
end; | |||
with gvAgent do begin | |||
Name := 'Restricted_1'; | |||
OptionsCustomize.ColumnFiltering := False; | |||
DataController.DataSource := dsAgent; | |||
OptionsView.Footer := True; | |||
OptionsView.ColumnAutoWidth := True; | |||
OptionsView.GroupByBox := False; | |||
OptionsData.Editing := False; | |||
end; | |||
with gvAgent.DataController.Summary do begin | |||
BeginUpdate; | |||
try | |||
with TcxGridDBTableSummaryItem(FooterSummaryItems.Add) do begin | |||
Column := gvAgent.GetColumnByFieldName('Description'); | |||
Position := spFooter; | |||
Kind := skCount; | |||
Format := 'Count = #'; | |||
end; | |||
finally | |||
EndUpdate; | |||
end; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')); | |||
btnProfit := TcxButton(Self.FindComponent('BtnProfitEstimator')); | |||
gvDocDetail := TcxGridDBTableView(Self.FindComponent('gvDocDetail')); | |||
cxAgent := TcxDBExtLookupComboBox.Create(btnProfit); | |||
PrepareXML; | |||
CreateTable; | |||
if Assigned(btnProfit) then begin | |||
lbAgent := TLabel.Create(btnProfit); | |||
with lbAgent do begin | |||
Parent := btnProfit.Parent; | |||
Name := 'lbAgent2'; | |||
Width := 100; | |||
Left := btnProfit.Left + btnProfit.Width +6; | |||
Top := btnProfit.Top; | |||
Caption := 'Agent 2'; | |||
end; | |||
with cxAgent do begin | |||
Parent := btnProfit.Parent; | |||
Top := btnProfit.Top; | |||
Left := btnProfit.Left + btnProfit.Width + lbAgent.Width+12; | |||
Height := btnProfit.Height; | |||
Width := 200; | |||
DataBinding.DataSource := M; | |||
DataBinding.DataField := 'UDF_Agent2'; | |||
Properties.View := gvAgent; | |||
Properties.KeyFieldNames := 'Code'; | |||
Properties.ListFieldItem := gvAgent.GetColumnByFieldName('Description'); | |||
Properties.DropDownListStyle := lsFixedList; | |||
Properties.ImmediatePost := True; | |||
Properties.DropDownWidth := 400; | |||
EditValue := 0; | |||
end; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 44 - Disable Terms Field=== | |||
Below is Example is disable the Terms Field in Sales Invoice | |||
Last Script Update : 07 Apr 2020<br /> | |||
Level : Basic | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var edTerms : TcxDBExtLookupComboBox; | |||
begin | |||
edTerms := Self.FindComponent('edTerms') as TcxDBExtLookupComboBox; | |||
if Assigned(edTerms) then | |||
edTerms.Enabled := False; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 45 - Export CSV/TXT Data=== | |||
Below is Example are doing following actions | |||
* Export Data to CSV/TXT from Invoice | |||
Last Script Update : 14 May 2020<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales Invoice''' | |||
:03. Right Click the '''Sales Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var lSL : TStringList; | |||
btnMoveDown : TSpeedButton; | |||
btn1 : TcxButton; | |||
M, D : TDataSet; | |||
procedure GetData; | |||
var s : string; | |||
begin | |||
D.First; | |||
while not D.Eof do begin | |||
s := M.FindField('DocNo').AsString + '|' + | |||
M.FindField('Code').AsString + '|' + | |||
D.FindField('ItemCode').AsString + '|' + | |||
D.FindField('Description').AsString + '|' + | |||
D.FindField('Qty').AsString + '|' + | |||
D.FindField('UnitPrice').AsString + '|' + | |||
D.FindField('Tax').AsString + '|' + | |||
D.FindField('TaxAmt').AsString + '|' + | |||
D.FindField('Disc').AsString + '|' + | |||
D.FindField('Amount').AsString; | |||
lSL.Append(s); | |||
D.Next; | |||
end; | |||
end; | |||
procedure OnClick1(Sender: TObject); | |||
var lFileName, lFilter : string; | |||
begin | |||
lFilter := 'Texts Files (*.txt, *.csv)|*.txt;*.csv|All Files (*.*)|*.*'; | |||
lFileName := 'SL_IV_' + FormatDateTime('YYYYMMDD', M.FindField('DocDate').Value); | |||
lSL := TStringList.Create; | |||
try | |||
if PromptForFileName(lFileName, lFilter, 'txt', 'Save As...', '.', True) then begin | |||
GetData; | |||
lSL.SaveToFile(lFileName); | |||
MessageDlg('Export Done', mtInformation, [mbOk], 0); | |||
end; | |||
finally | |||
lSL.Free; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')).Dataset; | |||
D := TDataSource(Self.FindComponent('dsDocDetail')).Dataset; | |||
btnMoveDown := TSpeedButton(Self.FindComponent('BtnMoveDown')); | |||
btn1 := TcxButton.Create(btnMoveDown); | |||
if Assigned(btnMoveDown) then begin | |||
with btn1 do begin | |||
Parent := btnMoveDown.Parent; | |||
Top := btnMoveDown.Top; | |||
Left := btnMoveDown.Left + btnMoveDown.Width + 120; | |||
Height := btnMoveDown.Height; | |||
Width := 100; | |||
Caption := '&1. Button'; | |||
OnClick := @OnClick1; | |||
ShowHint := True; | |||
Hint := 'Button Click 1'; | |||
end; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 46 - Run External Application=== | |||
Below is Example are doing following actions | |||
* Auto Run SQL Payroll | |||
Last Script Update : 19 Jun 2020<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Agent''' | |||
:03. Right Click the '''Agent''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnOpen''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnOpen Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var FWshShell : Variant; | |||
C : TComponent; | |||
BtnBrowse, btn2 : TcxButton; | |||
function ComWshShell: Variant; | |||
begin | |||
if FWshShell = Null then begin | |||
FWshShell := CreateOleObject('WScript.Shell'); | |||
end; | |||
Result := FWshShell; | |||
end; | |||
procedure OnClick2(Sender: TObject); | |||
begin | |||
FWshShell := Null; | |||
try | |||
ComWshShell.Exec('C:\estream\SQL Payroll\bin\SQLPay.exe'); | |||
finally | |||
FWshShell := Null; | |||
end; | |||
end; | |||
begin | |||
C := Self.FindComponent('frDataSetButton1'); | |||
BtnBrowse := TcxButton(C.FindComponent('btnViewDetail')); | |||
btn2 := TcxButton.Create(C); | |||
if Assigned(C) then begin | |||
with btn2 do begin //Create Below the Browse Button | |||
Parent := TwinControl(c); | |||
Top := BtnBrowse.Top + BtnBrowse.Height + 5; | |||
Height := BtnBrowse.Height; | |||
Left := BtnBrowse.Left | |||
Width := BtnBrowse.Width; | |||
Caption := '&2. Payroll'; | |||
OnClick := @OnClick2; | |||
ShowHint := True; | |||
Hint := 'Open Payroll App.'; | |||
end; | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 47 - Update Same UDF in Sales Invoice in Customer Invoice=== | |||
Below is Example are doing following actions | |||
* Auto update UDF_VehicleNo in Sales Invoice to UDF_VehicleNo in Customer Invoice | |||
Last Script Update : 09 Mar 2021<br /> | |||
Level : Advance | |||
'''Steps - OnOpen''' | |||
:01. Click '''Tools | DIY | SQL Control Center...''' | |||
:02. At the left panel look for '''Sales''' | |||
:03. Right Click the '''Invoice''' | |||
:04. Select '''New Event''' | |||
:05. Enter any name (eg Calc) in the '''Name''' field (Only Alphanumeric & no spacing) | |||
:06. Select '''OnAfterSave''' for '''Event''' field | |||
:07. Click OK | |||
:08. Click the Calc (name create at Step 5 above) on the left panel | |||
:09. Copy below script & paste to the Right Panel (Script Section) | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! OnAfter Script | |||
|- | |||
| | |||
<syntaxhighlight lang="delphi"> | |||
var FComServer : Variant; | |||
M : TDataSet; | |||
function ComServer: Variant; | |||
begin | |||
if FComServer = Null then begin | |||
FComServer := CreateOleObject('SQLAcc.BizApp'); | |||
end; | |||
Result := FComServer; | |||
end; | |||
function VarToStrDef(const V: Variant; const ADefault: string): string; | |||
begin | |||
if not VarIsNull(V) then | |||
Result := V | |||
else | |||
Result := ADefault; | |||
end; | |||
function VarToStr(const V: Variant): string; | |||
begin | |||
Result := VarToStrDef(V, ''); | |||
end; | |||
procedure UpdateARIV; | |||
var lDockey, lBizObj, lMain : Variant; | |||
lDocNo : String; | |||
begin | |||
lDocNo := M.FindField('DocNo').AsString; | |||
try | |||
FComServer := null; | |||
lBizObj := ComServer.BizObjects.Find('AR_IV'); | |||
lMain := lBizObj.DataSets.Find('MainDataSet'); | |||
lDocKey := lBizObj.FindKeyByRef('DocNo', lDocNo); | |||
lBizObj.Params.Find('DocKey').Value := VarToStr(lDocKey); | |||
if not VarIsNull(lDocKey) then begin | |||
lBizObj.Open; | |||
lBizObj.Edit; | |||
lMain.FindField('UDF_VehicleNo').AsString := M.FindField('UDF_VehicleNo').AsString; | |||
lBizObj.Save; | |||
end; | |||
finally | |||
lBizObj.Close; | |||
lBizObj := null; | |||
FComServer := null; | |||
end; | |||
end; | |||
begin | |||
M := TDataSource(Self.FindComponent('dsDocMaster')).Dataset; | |||
UpdateARIV; | |||
end. | |||
</syntaxhighlight> | |||
|} | |||
:10. Click '''Save''' button | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
===Example 48 - === | |||
* More Coming Soon.... | |||
<div style="float: right;"> [[#top|[top]]]</div> | |||
==FAQ== | |||
===Why when click '''Compile Script''' button prompt error '''[Error] (xx:xx):Unknown identifier 'Dataset''''=== | |||
: This happen if you doing script on the event '''OnGridColumnValueChanged''' & can ignore the error if you confirm your script is correct. | |||
===How do I know my script is correct when using the script on the event '''OnGridColumnValueChanged''' ?=== | |||
: You can add below script at 1st line before you click '''Compile Script''' button but remember to remove it before you click '''Save''' button. | |||
<syntaxhighlight lang="delphi"> | |||
var EditingField, Dataset :Variant; | |||
</syntaxhighlight> | |||
===How many data source (TDatasource) it had for data entry (eg Sales Invoice) & what is each name?=== | |||
: Generally it had 3 data source & some had extra 1 (i.e. total 4). | |||
: Below is the list & detail | |||
: Below is the list & detail | |||
{| class="wikitable" style="margin: 1em auto 1em auto;" | |||
{| class="wikitable" style="margin: 1em auto 1em auto;" | |||
Line 4,401: Line 2,436: | |||
|} | |||
|} | |||
- | |||
===How to check the Record in Edit Mode?=== | |||
+ | |||
04. How to check the Record in Edit Mode? | |||
: You can use below script | |||
: You can use below script | |||
<syntaxhighlight lang="delphi"> | |||
<syntaxhighlight lang="delphi"> | |||
Line 4,415: Line 2,450: | |||
</syntaxhighlight> | |||
</syntaxhighlight> | |||
- | |||
===Using Form Mode - Split Browse & Detail Windows Option Prompt '''Null Pointer Exception Error'''=== | |||
+ | |||
05. | 05. | ||
- | |||
: You can use below script | |||
<syntaxhighlight lang="delphi"> | |||
... //yr other code | |||
begin | |||
if TWinControl(Self.FindComponent('DetailControl')).Visible then begin | |||
...//yr other code | |||
end; | |||
end. | |||
</syntaxhighlight> | |||
===Message Dialog with Option=== | |||
<syntaxhighlight lang="delphi"> | |||
... //yr other code | |||
begin | |||
if MessageDlg('Are you sure?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then | |||
MessageDlg('Yes Click', mtInformation, [mbOK],0) else | |||
MessageDlg('No Click', mtInformation, [mbOK],0); | |||
end. | |||
</syntaxhighlight> | |||
==See also== | ==See also== |
Revision as of 02:16, 9 July 2021
Menu: Tools | DIY | SQL Control Center...
Introduction
This is Additional Module(DIY Script Module) which allow user to override or customise the SQL System.
The Language use is Pascal
DIY Script
Available Action/Event
Action/Event | Description |
---|---|
OnOpen | The script trigger On Open the Form (eg On Open the Sales Invoice Form) |
OnClose | The script trigger On Close/Exit the Form (eg on Exit Sales Invoice Form) |
OnBeforeNew | The script trigger before the build in New Button action execute. |
OnAfterNew | The script trigger after the build in New Button action Execute. |
OnBeforeEdit | The script trigger before the build in Edit Button action execute. |
OnAfterEdit | The script trigger after the build in Edit Button action Execute. |
OnBeforeDelete | The script trigger before the build in Delete Button action execute. |
OnAfterDelete | The script trigger after the build in Delete Button action Execute. |
OnBeforeSave | The script trigger before the build in Save Button action execute. |
OnAfterSave | The script trigger after the build in Save Button action Execute. |
OnBeforeCancel | The script trigger before the build in Cancel Button action execute. |
OnAfterCancel | The script trigger after the build in Cancel Button action Execute. |
OnBeforePrint | The script trigger before the build in Print or Preview Button action Execute. |
OnGridBeforeInsert | The script trigger before the build in + Button action Execute. |
OnGridAfterInsert | The script trigger after the build in + Button action Execute. |
OnGridBeforePost | The script trigger before post the current row record. |
OnGridAfterPost | The script trigger after post the current row record. |
OnGridBeforeDelete | The script trigger before the build in - Button action Execute. |
OnGridAfteDelete | The script trigger after the build in - Button action Execute. |
OnGridBeforeCancel | The script trigger before cancel the current row record. |
OnGridAfterCancel | The script trigger after cancel the current row record. |
OnGridColumnValueChanged | The script trigger on changes value in the current record. |
Example 1 - Get UDF & Do Calculation
Below is Example are doing following actions
- Get UDF_Length & UDF_Width from Maintain Item UDF Fields
- Do Calculation Qty := UDF_Length * UDF_Width * UDF_Rate
Last Script Update : 23 Oct 2017
Level : Basic
Steps - OnGridColumnValueChanged
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnGridColumnValueChanged for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnGridColumnValueChanged Script |
---|
- 10. Click Save button
- ----------------------------------------------------------------------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------------------------------
Example 2 - Change Title Caption
Below is Example are doing following actions
- Change the Sales Quotation Title to My Quotation
Last Script Update : 19 Oct 2015
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 3 - Get UDF From Maintain Customer
Below is Example are doing following actions
- At Sales Invoice On Select Customer Code prompt UDF_MSG from Maintain Customer
Last Script Update : 20 Oct 2015
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 4 - Get Transfer Information - QT to IV
Below is Example are doing following action
- Quotation direct Transfer to Invoice.
- Get the Invoice number, Date & Qty which had transferred to Invoice in the Quotation and shown it below the Browse button
Last Script Update : 30 Oct 2015
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 5 - Only Enable Some of the field on Click Edit by User
Below is Example are doing following action in Sales Cash Sales
- Set all Field to Read Only at Header except Agent, DocNo, DocRef1, DocNoEx & UDF_Expired
- Set all Detail Field to Read Only except Description & Account Field
Remember to Enable Back by Disable the GetAuthorised (see below) Script & Insert it to OnBeforeNew script
Cons : It will be delay about 3 to 4 sec. after click Edit & New button
Last Script Update : 03 Nov 2015
Level : Advance
Steps - OnBeforeEdit & OnBeforeNew
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Cash Sales
- 03. Right Click the Sales Cash Sales
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeEdit for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeEdit Script |
---|
- 10. Click Save button
Example 6 - Calculate Age between 2 date
Below is Example are doing following actions
- Do Calculation UDF_Age := UDF_DateTo - UDF_DateFrom
Last Script Update : 19 Nov 2015
Level : Basic
Steps - OnGridColumnValueChanged
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnGridColumnValueChanged for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnGridColumnValueChanged Script |
---|
- 10. Click Save button
Example 7 - Simple DropDown Selection List
Below is Example are doing following actions
- Create Label
- Create a drop down list at Maintain Customer for UDF_SearchKey
Last Script Update : 26 Mar 2018
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Customer
- 03. Right Click the Customer
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 8 - Auto Add Service Charge
Below is Example are doing following actions
- Auto Append ItemCode SERVICE
- Do Calculation for ItemCode SERVICE UnitPrice := Total Doc Amount (Excluding GST) * 0.1 & Round to 2 decimal point
Last Script Update : 12 Mar 2016
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 9 - Auto Click Profit Estimator Button
Below is Example are doing following actions
- Auto Click the Profit Estimator button
Last Script Update : 02 Dec 2015
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 10 - Simulate build-in Calculation using UDF Fields
Below is Example are doing following actions
- Get Discount Amount
- Get Tax Amount
- Do Calculation Amt := (UDF_UnitPrice*UDF_Qty)-UDF_Disc)*(TaxRate)
Last Script Update : 03 Sep 2016
Level : Basic
Steps - OnGridColumnValueChanged
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnGridColumnValueChanged for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnGridColumnValueChanged Script |
---|
- 10. Click Save button
Example 11 - Auto Click Edit, Save & Browse Button
Below is Example are doing following actions
- Select Record at Grid
- Auto Click Browse button
- Auto Click Edit button
- Auto Click Save button
- Auto Click Browse button
Last Script Update : 20 Apr 2019
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 12 - Get Current User Name and Current Working Date
Below is Example are doing following actions
- Set Current Login User ID & Current Working Date to UDF
Last Script Update : 22 Dec 2015
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 13 - Get Excel Data
Below is Example are doing following actions
- Get Data from Excel & append to detail
Last Script Update : 14 Jan 2016
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 14 - Copy To & Paste From Clipboard
Below is Example are doing following actions
- Copy string to Clipboard
- Paste from Clipboard
Last Script Update : 14 Jan 2016
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 15 - Get CSV/TXT Data
Below is Example are doing following actions
- Get Data from CSV/TXT & append to detail
Last Script Update : 03 Mar 2018
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 16 - Set Default Filtering For Sales Report
Below is Example are doing following actions
- Filter by Agent in Sales Document Listing
- Disable Selection for Agent
Last Script Update : 02 Feb 2016
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Document Listing
- 03. Right Click the Sales Document Listing
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 17 - Copy RefCost to UDF At Maintain Item
Below is Example are doing following actions
- Set UDF_CommCost := RefCost * 1.1 (round to 2 decimal)
Last Script Update : 03 Mar 2016
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Stock Item
- 03. Right Click the Stock Item
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 18 - Recalculate Formula Done at OnGridColumnValueChanged Script for Transferred Document
Below is Example are doing following actions
- Recalculate the Formula Done at OnGridColumnValueChanged
- Copy Original fields (eg Qty) to UDF fields for Transfer Items
- Copy UDF fields (eg UDF_Qty) to Original fields for Non Transfer Items
Last Script Update : 12 Mar 2016
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 19 - Hide Stock Opening Grid In Maintain Item
Below is Example are doing following actions
- Hide the Grid & Navigator Button for Opening Balance
Last Script Update : 13 Apr 2016
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Stock Item
- 03. Right Click the Stock Item
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 20 - Export Data To Excel
Below is Example are doing following actions
- Export Maintain Agent List to Excel
Last Script Update : 26 May 2016
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Agent
- 03. Right Click the Agent
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 21 - Change DocRef 1 Label
Below is Example are doing following actions
- Change the Purchase Order DocRef1 Label to C.PO # :
Last Script Update : 09 Jul 2021
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Purchase Order
- 03. Right Click the Purchase Order
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 22 - Add Click Button
Below is Example are doing following actions
- Create 2 buttons at Sales Quotation
- 1 at Beside Up Down Button
- 1 at Below Browse Button
Last Script Update : 16 Dec 2017
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 23 - Using TxQuery
Below is Example are doing following actions
- Create 1 button at Sales Quotation to Get Total Base Quantity
Last Script Update : 02 Nov 2016
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 24 - How to find component in different Event?
Below is Example are doing following actions
- Create 1 button at Sales Quotation
- On Before Save will auto Click the New Created button
Last Script Update : 24 Dec 2016
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 25 - Simple DropDown Selection List in Document Detail
Below is Example are doing following actions
- Create a drop down list at Sales Invoice Detail for UDF_DeliveryType
Last Script Update : 27 Dec 2016
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 26 - Default Company Code & Payment Method In Sales Cash Sales
Below is Example are doing following actions
- On Click New auto Set Default for
- - Customer Code := 300-C0001
- - Payment Method := 320-000
- - Payment Project := ----
Last Script Update : 28 Dec 2016
Level : Basic
Steps - OnAfterNew
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Cash Sales
- 03. Right Click the Sales Cash Sales
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnAfterNew for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnAfterNew Script |
---|
- 10. Click Save button
Example 27 - Get Transfer Information - QT to DO to IV
Below is Example are doing following action
- Quotation Transfer to Delivery Order to Invoice.
- Get the Quotation number, Date & Qty in the Invoice and shown it below the Browse button
Last Script Update : 03 Jun 2017
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 28 - Approval by User if Document Amount Exceed Limit
Below example is to prompt Authorised if the Document Amount Exceed the limit (eg 10000) in Sales Invoice
Last Script Update : 20 Jul 2017
Level : Advance
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 29 - Add DB Check Box
Below example is to create DBCheckBox at Header in Sales Order
Last Script Update : 07 Aug 2017
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Order
- 03. Right Click the Sales Order
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 30 - Set Default 14 days delivery date from DocDate
Below example is to set Default 14 Days from Document Date in Sales Quotation
Last Script Update : 20 Sep 2017
Level : Basic
Steps - OnGridAfterInsert
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnGridAfterInsert for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnGridAferInsert Script |
---|
- 10. Click Save button
Example 31 - Add TcxDBTextEdit
Below example is to Create new TcxDBTextEdit for UDF_Wastage in Maintain Item
Last Script Update : 21 Dec 2017
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Stock
- 03. Right Click the Stock Item
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 32 - Call Report Object In Script
Below example is to Create new Button to calculate Margin for each Invoice & update to Header UDF_Margin field
Last Script Update : 23 Nov 2017
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 33 - Set Discount to Empty for next line
Below is Example will automatic remove the Discount field value on insert next item line.
Last Script Update : 27 Nov 2017
Level : Basic
Steps - OnGridAfterInsert
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnGridAfterInsert for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnGridAfterInsert Script |
---|
- 10. Click Save button
Example 34 - Prompt Dialog for Discount
Below is Example are doing following actions
- Auto Append ItemCode DISC
- Do Calculation for ItemCode DISC UnitPrice := Total Doc Amount * Rate Enter
Last Script Update : 29 Nov 2017
Level : Basic
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 35 - Create New Grid Tab on Existing Grid
Below is Example are create new Tab in Existing Grid in Customer Due Listing
Last Script Update : 03 Jan 2018
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Customer Due Document
- 03. Right Click the Customer Due Document
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 36 - How to Detect what is the Current Doc Type in Document Listing?
Last Script Update : 10 Aug 2018
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Document Listing
- 03. Right Click the Sales Document Listing
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 37 - Simple Copy From Dataset to New Doc
Below is Example to Copy Quotation Information to Sales Invoice
Last Script Update : 08 Sep 2018
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Quotation
- 03. Right Click the Sales Quotation
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 38 - Create New Column on Existing Grid
Below is Example to Add UDF_Margin in the Sales Document Listing
This only work if in Report Designer in Main Pipeline/Table had the field(s)
Last Script Update : 19 Feb 2019
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Document Listing
- 03. Right Click the Sales Document Listing
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 39 - Auto Click Apply button and Change the report Grid Data
Below Example is to Change Header & Detail Description field in Sales Document Listing
Last Script Update : 21 Mar 2019
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Document Listing
- 03. Right Click the Sales Document Listing
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 40 - Update DocNo To other Document
Below Example is to Update UDF_ORNo in Sales Invoice for Knock-off Payment from Customer Payment
Last Script Update : 03 Jul 2019
Level : Advance
Steps - OnAfterSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Customer Payment
- 03. Right Click the Customer Payment
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnAfterSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnAfterSave Script |
---|
- 10. Click Save button
Example 41 - How to Reset the Serial Number When update Location Field?
Below Example is to Set Back the Serial Number List when Location change/Updated
Last Script Update : 19 Oct 2020
Level : Advance
Steps - OnBeforeSave
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnBeforeSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnBeforeSave Script |
---|
- 10. Click Save button
Example 42 - How to find component in Advance Form?
Below Example is to change the label in Advance Form
Last Script Update : 23 Jan 2020
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 43 - DropDown List from Maintenance List
Below is Example are doing following actions
- Create Label
- Create a drop down list at Sales Invoice for UDF_Agent2
Last Script Update : 07 Apr 2020
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 44 - Disable Terms Field
Below is Example is disable the Terms Field in Sales Invoice
Last Script Update : 07 Apr 2020
Level : Basic
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 45 - Export CSV/TXT Data
Below is Example are doing following actions
- Export Data to CSV/TXT from Invoice
Last Script Update : 14 May 2020
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales Invoice
- 03. Right Click the Sales Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 46 - Run External Application
Below is Example are doing following actions
- Auto Run SQL Payroll
Last Script Update : 19 Jun 2020
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Agent
- 03. Right Click the Agent
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnOpen for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnOpen Script |
---|
- 10. Click Save button
Example 47 - Update Same UDF in Sales Invoice in Customer Invoice
Below is Example are doing following actions
- Auto update UDF_VehicleNo in Sales Invoice to UDF_VehicleNo in Customer Invoice
Last Script Update : 09 Mar 2021
Level : Advance
Steps - OnOpen
- 01. Click Tools | DIY | SQL Control Center...
- 02. At the left panel look for Sales
- 03. Right Click the Invoice
- 04. Select New Event
- 05. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
- 06. Select OnAfterSave for Event field
- 07. Click OK
- 08. Click the Calc (name create at Step 5 above) on the left panel
- 09. Copy below script & paste to the Right Panel (Script Section)
ExpandOnAfter Script |
---|
- 10. Click Save button
Example 48 -
- More Coming Soon....
FAQ
Why when click Compile Script button prompt error [Error] (xx:xx):Unknown identifier 'Dataset'
- This happen if you doing script on the event OnGridColumnValueChanged & can ignore the error if you confirm your script is correct.
How do I know my script is correct when using the script on the event OnGridColumnValueChanged ?
- You can add below script at 1st line before you click Compile Script button but remember to remove it before you click Save button.
var EditingField, Dataset :Variant;
How many data source (TDatasource) it had for data entry (eg Sales Invoice) & what is each name?
- Generally it had 3 data source & some had extra 1 (i.e. total 4).
- Below is the list & detail
- Below is the list & detail
-
How to check the Record in Edit Mode?
+ 04. How to check the Record in Edit Mode?
- You can use below script
- You can use below script
<syntaxhighlight lang="delphi">
Line 4,415: Line 2,450:
</syntaxhighlight>
-
Using Form Mode - Split Browse & Detail Windows Option Prompt Null Pointer Exception Error
+ 05. -
- You can use below script
... //yr other code
begin
if TWinControl(Self.FindComponent('DetailControl')).Visible then begin
...//yr other code
end;
end.
Message Dialog with Option
... //yr other code
begin
if MessageDlg('Are you sure?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
MessageDlg('Yes Click', mtInformation, [mbOK],0) else
MessageDlg('No Click', mtInformation, [mbOK],0);
end.
See also
- DIY Fields
- Maintain DIY
- Others Customisation