{{indexmenu_n>1}} ====== Examples of VBScript codes====== \\ ===== VBScript Programming Templates===== \\ =====Code that browses a full collection===== \\ \\ **coll.filter**, adds an AND to the filter that the collection has currently applied in the **filter** attribute of the XML at the SQL of the collection, or to the filter defined by calling the contents, **coll.linkfilter** would be to change this one, also. (CAREFUL! when changing the filter of a collection, remember to restore it afterwards...) =====Browsing a collection/contents with few data===== \\ \\ =====Getting an object (row) from a collection, having the value of a field from such object===== \\ Dim obj ‘Buscamos el cliente en la coll Clientes, con el valor del ID del cliente. Set obj=appdata.getcollection("Clientes")("ID",CStr(This("IDCLIENTE"))) If not obj is nothing Then obj("PROXIMA")=This("PROXIMA") obj("OBSERVACIONES")=This("FICHA") obj.save End If Set obj=nothing \\ =====Getting an object (row) from a collection, by using an SQL with more than 1 field (FINDOBJECT)===== \\ AppData.PushValue objLoquesea lanza un objeto en edición. Set cCierre=AppData.GetCollection("Cierre") Set objCierre=cCierre.FindObject("NUMINCIDENCIA='"+This("NUMINCIDENCIA")+"' AND NUMPROGRESO='"+This("NUMPROGRESO")+"'") If objCierre Is Nothing Then set objCierre=cCierre.CreateObject objCierre("MAP_IDINCIDENCIA")=This("ID") objCierre("NUMINCIDENCIA")=This("NUMINCIDENCIA") objCierre("NUMPROGRESO")=This("NUMPROGRESO") ContarPiezas This("NUMINCIDENCIA"),This("NUMPROGRESO") objCierre("MAP_NUMPIEZAS")=This("MAP_NUMPIEZAS") cCierre.additem objCierre AppData.PushValue objCierre Else Appdata.failwithmessage -11888,"Ya ha ejecutado el cierre con anterioridad." End If \\ ===== Messages (msgBox showToast) Notifications Sounds ===== \\ We have several ways to show a message on screen.\\ \\ ^ Command ^ Description ^ | ui.MsgBox "Ejemplo", "Mensaje", 0 | "regular" message of the framework, to vanish, the user must click into the OK button. | | ui.ShowNotification 1, “Título”, “Mensaje” | Notification at the notifications top bar, an ID (1) will be specified in order if we want to modify the notification further on, we can use the same command with another message and the one that already did exist will be modified. | | ui.DismissNotification "1" | It deletes the Notification from the notifications top bar made with the "ShowNotification", we have to specify the ID (1) of the notification to specify the message we want to remove. The parameter is necessary to pass it like a string. | | ui.ShowToast "A new message has been received " | TOAST message from the operative system, see screenshot below. The message automatically vanishes after a couple of seconds on screen. | \\ **Example of code:** \\ ===== Node to go to a collection by passing a parameter (irColl) ===== \\ First, we should have a button to call this node:\\ \\ \\ The node code would be:\\ \\ 'Hemos llamado al nodo irColl pero podríamos haberlo llamado de cualquier otra forma. \\ ===== Node to exit from a collection (onback) ===== \\ We call it onback because in Android we have an event that attends the come back button that executes this node, in such a way that the button we put to exit and the Android come back button do the same.\\ \\ We should have an exit button or a back button to execute this node. \\ \\ \\ This is the code that executes as our button as the Android come back button.\\ \\ \\ ===== Node to move to another tab (showGroup) ===== \\ In this code, we also see how we can change dynamicaly a property, in this case, the background image of a frame.\\ ----- \\ \\ ===== CASE in SQL for COLORVIEW ===== \\ For those who need to consult about SQL...\\ \\ SELECT g.*,CASE WHEN g.APROBADO=0 THEN '#FFFFFF' ELSE '#00FF00' END as MAP_COLORVIEW FROM ##PREF##Gastos g \\ ===== MACRO of an user to filter contents ===== \\ We can create an user MACRO in a collection to replace on real time the SQL of a collection, being able to replace even the SQL of the full collection. \\ \\ \\ Once defined the macro at the collection, we can use it later to change the value of such macro and therefore changing the SQL.\\ \\ \\ ===== Code to Create/Edit/Delete a record from a contents ===== \\ 'Para poder dar de alta un registro en un contents tendríamos que pasarle el ID de la cabecera... function addContents(coll,campoenlace) Set CollCV=appdata.GetCollection(coll) Set ObjCV=CollCV.CreateObject ObjCV(campoenlace) = this("ID") CollCV.AddItem Empty,ObjCV AppData.PushValue ObjCV end function 'A esta función tenemos que pasarle la referencia al contents y el ID que queremos editar. function editContents(coll,idselected) Set CollCV=appdata.GetCollection(coll) Set ObjCV=CollCV.FindObject("ID="+Cstr(idselected)) if not ObjCV is nothing then AppData.PushValue ObjCV end if end function 'Realmente no borramos el registro físicamente, lo que hacemos es cambiar el campo de enlace con la cabecera 'o podemos ponerle un BAJA=1, para darlo de baja lógica. Posteriormente tendríamos un mantenimiento para 'eliminar estos registros del dispositivo (Para que no se replique el borrado físico del registro). function deleteContents(coll,idselected,campoenlace) result = ui.MsgBox("¿Esta seguro de que desea eliminar el registro seleccionado?","¡ALERTA!",4) if result=6 then Set CollCV=appdata.GetCollection(coll) Set ObjCV=CollCV.FindObject("ID="+Cstr(idselected)) if not ObjCV is nothing then ObjCV(campoenlace) = -9999 ObjCV.Save end if ObjCV = nothing CollCV = nothing end if end function \\ =====Displaying error by screen===== \\ \\ =====Types of errors===== \\ \\ =====Data validation by using PopValue and PushValue for the errors===== \\ To avoid saving a record with fields with certain values, as empty ones. \\ \\ **Appdata.PopValue** is to take the value of the rule fail, to give it later with **Appdata.PushValue**.\\ \\ It will be passed as a Long, from there the Clng.\\ \\ \\ =====Button with Script===== \\ CODE TO MAKE A BUTTON. \\ \\ It is composed of **3 nodes**:\\ \\ |**Node 1**|**Prop of the type "B" (button)**| It is the node that defines the place where it comes, title and to which node calls to execute its code. It has the method attribute that is the one that makes the call to the node that has its code, the name "ExecuteNode", is the name of the "method" node, and has to be called similarly (uppercase-lowercase).| |**Node 2**|**Node method** name="ExecuteNode"| It is a mandatory and fixed node. (IT IS NOT NECESSARY ALREADY, only in old framesorks.)| |**Node 3**|**Node in which the code that will be executed is put**.| The name is defined by the user, and as only requirement, is the node name, it has to be called equal (uppercase-lowercase) than the node to which the button node calls in its method attribute. | \\ \\ =====Notices Collection===== \\ NOTICES COLLECTION. \\ \\ =====Content Image===== \\ CONTENT IN IMAGE MODE.\\ \\ With this content the data will be displayed as a image, and the user, in some coordinates of it, will be entitled to put marks.\\ By making a click in this mark it will display the data relative to it, it would be as giving to a line from a regular content. \\ \\ We need to keep in mind that the example is to display in a first image a vehicle, and if it is given to one place of it, which will be able to be a tyre, a glass or a door, they wil come up several types of damages that such part of the vehicle can have. \\ \\ TWO CONTENTS IN A HEADING COLL. The first one is the image-type content, that has the attributes:\\ \\ |**viewmode**| TO INDICATE THAT THE CONTENT HAS TO BE DISPLAYED IN IMAGE MODE.| |**imgbk**| IT IS SAID THE IMAGE TO BE DISPLAYED.| \\ The other content is the one which is put underneath and according the place where the image content is marked, they will come up the relative data. \\ \\