You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Tips for writing a high-performance and secure script


When you request to copy an object to another object, you can do this without going to the database with the Set command.


// Reading the target container with the source container Id from database
Container.Get(@@Container.Id,@@Container2)
 
// Assigning source container object to target container without going to database
Set(@@Container2, @@Container)

The Get operation also auto-fills the linked objects within the read object. If you only need the main object, you can type the name of the object in the 2nd parameter of the Get command.

// This operation reads and fills in the @@Warehouse, @@WarehouseFloor, @@WarehouseZone, @@WarehouseBlock objects from the database along with the @@Address object.
Address.Get("Address='@AddressBarcode'")
 
// This operation only fills the @Address object with the address information read from the database.
Address.Get("Address='@AddressBarcode'",@Address)

All objects in the script are global. Once it is filled in, it stays filled unless it is reset or filled by another command. To avoid saving errors, you should reset the variables to affect the operation before the operation.

// ResetVariables command resets variables in memory.
ResetVariables({"name":["@@ProductionOrder","@@ProductionOrderLine","@@WorkOrder","@@WorkOrderLine","@@OrderSlip","@@OrderSlipLine","@@Arp"]})

You can call the frequently performed operations by transferring them to a common form, and you can make your script shorter and compacter.

Set(@AuthorizationCode, "ENTRY") // Assigning the authorization code to use for the address to the variable
CallForm(ListSelectAddress) //  Calling the address selection form
If(@AddressSelectionResult= -1,Goto(BasaDon)) //  Redirecting the script if the wrong result is returned from the form
 
BeginForm(ListSelectAddress) // Common address selection form
    Set(@AddressSelectionResult, 0) // Resetting result variable
    Address.List("AuthCode='@AuthorizationCode'","",@AddressList)
    If(@AddressList.rowCount<1)
        ShowMessage({"title":"WARNING","message":"No Address Defined","buttons":"OK"},@Option)
        Set(@AddressSelectionResult, -1) // Incorrect result variable
    Else()
        If(@AddressList.rowCount = 1) // If there is only one address, it is assigned directly to the @@Address variable
            Address.Get(@AddressList.rows.1.Id) 
        Else() // If there are more than one address, it is selected from the list
            PopupView(@AddressList.rows,{"mode":"list","title":"Acceptance Address List","fields":["Address|Address Definition|15|L"]},@order)
            Address.Get(@[email protected])
        EndIf()
    EndIf()
    ReturnForm() // Returning to the line that called this form
EndForm()

You can define your favorites once and use them everywhere in the script.

// Set command supports variable assignment in JSON structure.
Set(@OrderStatus, {"Pending":12,"Processing":13, "Completed":14})
 
// The order status is set as completed. The sub-objects of JSON objects can be accessed with . (dot).
CustomState.Get(@OrderStatus.Completed)

Do not use SQL command to fill in objects from the database unless necessary. The List and Get commands retrieve data by performing many checks, including permissions.

// It retrieves both the active and inactive warehouses of both the active and inactive company, whether it is authorized by that user.
Sql("SELECT * FROM SysWarehouse", @Warehouses)
 
// It retrieves only the active warehouses of the active company, which is authorized by that user.
Warehouse.List("","", @Warehouses)

Do not use SQL commands for database update operations unless necessary. The Save command performs many checks while saving.

// Updates the slip status as Integrated but does not trigger the integration.
Sql("UPDATE Slip SET StateId=19", @result)
 
// Updates the slip status as Integrated and integrates into ERP as an automatic action of that status.
CustomState.Get(19)
Slip.Save()