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

Compare with Current View Page History

« Previous Version 2 Next »

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='@AdresBarkod'")
 
// This operation only fills the @Address object with the address information read from the database.
Address.Get("Address='@AdresBarkod'",@Adres)

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(@YetkiKodu, "GIRIS") // Assigning the authorization code to use for the address to the variable
CallForm(AdresListeleSec) //  Calling the address selection form
If(@AdresSecimSonucu = -1,Goto(BasaDon)) //  Redirecting the script if the wrong result is returned from the form
 
BeginForm(AdresListeleSec) // Common address selection form
    Set(@AdresSecimSonucu, 0) // Resetting result variable
    Address.List("AuthCode='@YetkiKodu'","",@AdresListesi)
    If(@AdresListesi.rowCount<1)
        ShowMessage({"title":"UYARI","message":"Tanımlı Adres Bulunamadı","buttons":"TAMAM"},@Secenek)
        Set(@AdresSecimSonucu, -1) // Incorrect result variable
    Else()
        If(@AdresListesi.rowCount = 1) // Tek adres varsa direkt @@Address değişkenine atanıyor
            Address.Get(@AdresListesi.rows.1.Id)
        Else() // Birden çok adres varsa listeden seçip yaptırılıyor
            PopupView(@AdresListesi.rows,{"mode":"list","title":"Kabul Adres Listesi","fields":["Address|Adres Tanımı|15|L"]},@sira)
            Address.Get(@[email protected])
        EndIf()
    EndIf()
    ReturnForm() // Bu formu çağıran satıra geri dönülüyor
EndForm()

Sık kullandığınız sabitleri bir kez tanımlayıp, scriptin her yerinde kullanabilirsiniz.

// Set komutu JSON yapısında değişken atamasını destekler.
Set(@EmirDurum, {"Bekliyor":12,"IslemeAlindi":13, "Tamamlandi":14})
 
// Emir statüsü tamamlandı olarak belirleniyor. JSON nesnelerin alt nesnelerine . (nokta) ile erişilebilir.
CustomState.Get(@EmirDurum.Tamamlandi)

Gerekmedikçe, nesneleri veritabanından doldurmak için Sql komutu kullanmayın. List ve Get komutları, yetkiler dahil bir çok kontrolü yaparak verileri getirir.

// Kullanıcının yetkisi olduğu-olmadığı, aktif firmaya ait olan-olmayan, kullanımda olan-olmayan bütün depoları getirir.
Sql("SELECT * FROM SysWarehouse", @Depolar)
 
// Sadece aktif firmaya ait, kullanımda olan ve o kullanıcının yetkisi olan depoları getirir.
Warehouse.List("","", @Depolar)

Gerekmedikçe, veritabanında güncelleme işlemleri için Sql komutu kullanmayın. Save komutu kaydetme sırasında bir çok kontrolü yapar.

// Fiş statüsünü Entegre Edildi olarak günceller ama entegrasyonu tetiklemez.
Sql("UPDATE Slip SET StateId=19", @sonuc)
 
// Fiş statüsünü Entegre Edildi olarak günceller ve o statünün otomatik eylemi olarak ERP'ye entegre olmasını sağlar.
CustomState.Get(19)
Slip.Save()