Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer RedditRecent ChangesSend via e-MailPrintPermalink × Table of Contents Programming Templates Code that browses a full collection Browsing a collection/content with few data Getting an object (row) from a collection, having the value of a field of such object Getting an object (row) from a collection, using a SQL with more than a field (FINDOBJECT) Showing messages by screen Asking data to be able to work with them Showing error by screen Types of errors Data validation using PopValue and PushValue for the errors Button with Script Collection of notices Image Content Creating a Record with Script Putting value to a Global Variable Information Queue Device Programming Templates Code that browses a full collection <action name="runscript"> <script language="VBScript"> Dim coll, filtro ‘Variable con la coleccion que se va a utilizar Set coll =AppData.GetCollection("PresupuestosScript") ‘Guardamos el filtro que tiene la coleccion por defecto filtro=coll.filter ‘Le ponemos un filtro con el atributo filter, ‘que machacaría el filtro que ya tiene la coll en su atributo filter. coll.filter="MAP_SIMBTIPO='PR'" ‘Función para ejecutar el SQL de la coll, y poder recorrer los record que tiene dicha coll coll.StartBrowse ‘Utilizamos un while, preguntando si el registro actual es nulo o no. while not coll.CurrentItem is nothing if coll.CurrentItem("OPTIONS") = 0 then coll.currentItem("OPTIONS")=1 coll.currentItem.Save end if ‘Para pasar al siguiente registro de la coll coll.MoveNext wend ‘Siempre que se hace un StartBrowse, tiene que existir un EndBrowse, que es para cerrar la conexión. coll.EndBrowse ‘Restauramos el filtro original coll.filter=filtro Set coll=nothing </script> </action> In last versions of the platform it is just Filter, which will have the filter that currently has applied the collection, linkfilter it is not interpreted anymore. (Filter replaces Linkfilter) Browsing a collection/content with few data <action name="runscript"> <script language="VBScript"> Dim colldet,j,i,valor ‘Cogemos la coll contents Detalles del objeto actual This. Set colldet=this.contents("Detalles") j=0 ‘Guardamos en la variable i el número de registros que tiene el content. i=this.contents("Detalles").count ‘Si es cero se pueden dar dos opciones: ‘ - Que no haya ningún registro ‘ - Que aún no se haya cargado el content y por eso no tengamos ningún registro ‘Así que le hacemos un loadall para cargarlos todos (si no están cargados), y si no hubiera ‘registros no pasaría nada al hacer el loadall. ‘El loadall cuidado con su uso, ya que si tiene muchos elementos, nos quedaremos sin memoria. ‘El máximo número de registros de una colección para cargarla con loadall podemos fijarla en 20 ‘claro está, todo depende de lo grande que sea cada registro de dicha colección. if i=0 then this.contents("Detalles").loadall i=this.contents("Detalles").count end if ‘Utilizamos un For para recorrer los registros del contents. For j=0 to i-1 ‘Tomamos el valor del content con el indice de dicho registro. valor=colldet(j)("IDARTICULO") if valor="loquesea" then ‘ Realizar la función deseada end if next ‘Liberamos memoria. Set colldet=nothing </script> </action> Getting an object (row) from a collection, having the value of a field of 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, using a SQL with more than a 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 Showing messages by screen We have several ways to show a message on screen. Command Description ui.MsgBox “Ejemplo”, “Mensaje”, 0 “ordinary” message of the framework, to disappear, the user must press the OK button. ui.ShowNotification 1, “Título”, “Mensaje” Notification at the top bar of notifications, an ID is specified (1) 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 top bar of notifications by making with the “ShowNotification”, we have to specify the ID (1) of the notification to specify the message we want to remove. ui.ShowToast “A new message has been received ” TOAST Message of the operative system, see the screenshot below. The message disappears automatically after a couple of seconds on screen. Example of code: <!-- En este caso vamos a hacer uso del nodo replica-ok, para capturar el evento de cuando recibimos operaciones en la tabla gen_mensajeria --> <replica-ok-gen_mensajeria> <action name="runscript"> <script language="VBScript"> 'AppData.UserInterface.MsgBox hace exactamente lo mismo, ui es una abreviatura de AppData.UserInterface. ui.MsgBox "Ejemplo", "Mensaje", 0 ui.ShowNotification 1, “Título”, “Mensaje” (el primer parámetro es el ID por si hay que modificarla luego) ui.ShowToast "Se ha recibido un nuevo mensaje " </script> </action> </replica-ok-gen_mensajeria> Asking data to be able to work with them 'Con esta ventana se piden datos de tipo texto y se guardan en la variable s1. s1 =appdata.userinterface.getinputstring ("Mensaje de la Ventana","Valor Ventana",0) 'En esta ventana, SOLO se le pide datos de tipo numéricos y se guardan en la variable s2. s2 =appdata.userinterface.getinputstring ("Mensaje de la Ventana","Valor Ventana",1) s="El Presupuesto: " + cstr(s1) + " tiene el valor: " + cstr(s2) 'Solo muestra mensaje d=appdata.userinterface.msgbox (cstr(s),"Presupuesto",0) 'Muestra un mensaje con aceptar o cancelar. Guarda en la variable a el botón pulsado. a=appdata.userinterface.msgbox (cstr(s),"Presupuesto",1) if a=1 then ‘Entra aquí porque se le dio a Aceptar. else ‘Entra aquí porque se le dio a Cancelar. end if This section in the new platforms (Android, Iphone, Windows Phone…) is already DEPRECATED Showing error by screen <script language="VBScript"> if this("IDCLIENTE")= 0 then Appdata.FailWithMessage -8100,"¡¡No ha seleccionado un cliente.!!" end if 'SCRIPT PARA REALIZAR LA VALIDACION DE LOS DETALLES, QUE SE MIRA SI EL CAMPO IDTARIFA 'ESTA LLENO O NO. SI DA ERROR, MUESTRA UN MENSAJE DE TIPO -8100, PARA DECIR QUE ES ERROR. Dim i,j Dim colldet Set colldet=this.contents("DetallesCabecera") j=0 i=this.contents("DetallesCabecera").count if i=0 then this.contents("DetallesCabecera").loadall end if i=this.contents("DetallesCabecera").count while i <> 0 valor=colldet(j)("IDTARIFA") if valor=0 then i=0 aux=1 else i=i-1 j=j+1 end if if aux=1 then Appdata.FailWithMessage -8100,"¡¡Hay Detalles sin Tarifa!!" wend </script> Types of errors <script language="VBScript"> 'ERROR DISPONIBLE EN TODAS LAS PLATAFORMAS 'Muestra un mensaje de error con el texto que le pongamos appdata.failwithmessage -8100,"Mensaje de error" 'ERRORES DISPONIBLES EN PLATAFORMA POCKET PC 'Muestra un mensaje de error con el texto que le pongamos appdata.failwithmessage -7500,"Mensaje de warning" 'Refresca la cabecera cuando se ejecuta con el Selecteditem. YA NO ES NECESARIO. appdata.failwithmessage -666,"Mensaje de información" 'Mensaje de informacion con icono de Información appdata.failwithmessage -11888,"Mensaje que queremos mostrar" 'Mensaje personalizado con posiblidad de bloqueo con botón. appdata.failwithmessage -11822,"Mensaje de información" 'Mensaje propio de CGS appdata.failwithmessage -11811,"Mensaje de información" 'Inicia la replica desde un script Appdata.FailWithMessage -8100,"##STARTREPLICA##" 'Esta macro funciona conjuntamente con CGStart (kiosko de PDA). 'Cierra el frame y le dice al kiosko q reinicie la PDA. 'Si el kiosko no está instalado, simplemente se cierra la aplicación. Appdata.FailWithMessage -8100,"##RESETAPP##" 'Salir de la aplicacion. Appdata.FailWithMessage -8100,"##EXITAPP##" 'Usado para salir de las ventanas de Nomen y Edit. Appdata.FailWithMessage -8100,"##EXIT##" </script> Data validation using PopValue and PushValue for the errors Prevent it from being saved a record with fields with some values, such as the empty ones. Appdata.PopValue it is to take the fail value of the rule, to give it later with Appdata.PushValue . It will be passed like a Long, from there the Clng. <insert> <rule name="fail-if-not-valid"> <rule name="runscript" msg="Faltan por rellenar campos obligatorios."> <script language="VBScript"> Dim bFail,x x =AppData.PopValue bFail =0 if This("FECHANAC") <> "" then if This("DNI")<>"" AND bFail=0 then bFail=0 else bFail=1 end if if This("PROVINCIA")<>"" AND bFail=0 then bFail=0 else bFail=1 end if if This("CALLE")<>"" AND bFail=0 then bFail=0 else bFail=1 end if if This("IDPROPIETARIO")<>"" AND bFail=0 then bFail=0 else bFail=1 end if if bfail=0 then This("%FALTANDATOS")=0 else This("%FALTANDATOS")=1 end if Else This("%FALTANDATOS")=1 end if AppData.PushValue (CLng(bFail)) </script> </rule> </rule> </insert> Button with Script CODE TO MAKE A BUTTON. It is made up of 3 nodes: Node 1 Prop of type “B” (button) It is the node that defines the place where the same title comes up, and which node it 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” name, and it has to be called in the same way (uppercase-lowercase). Node 2 method Node name=“ExecuteNode“ It is a mandatory and fixed node. (IT IS NOT ANYMORE NECESSARY, only in old frameworks). Node 3 Node in which the code that is going to be executed is put. The name is defined by the user, and as only requirement, it is the node name, it has to be called in the same way (uppercase-lowercase) than the node to which the button node calls to in its method attribute. <prop name="Iniciar" group="3" type="B" method="ExecuteNode (inicializar)" title="Iniciar Ruta" visible="1" toolbar="false" labelwidth="24" onchange="refresh255" lmargin="7"/> <method name="ExecuteNode"> <param name="P1" type="T" value=""/> </method> <inicializar> <action name="runscript"> <script language="VBScript"> Dim vResult vResult =AppData.UserInterface.MsgBox ("Esta acción reiniciará toda la ruta. ¿Está seguro que desea ejecutarla?","Advertencia",1) If vResult =1 Then appdata.executeSQL "UPDATE Gen_Rutas SET VISITADO=0 WHERE IDUSUARIO=" + CStr(This("IDUSUARIO")) vResult =AppData.UserInterface.MsgBox ("Ruta inicializada","Advertencia",0) End If </script> </action> </inicializar> Collection of notices COLLECTION OF NOTICES. <coll name="Avisos" title="el aviso" sql="SELECT d.ID FROM (##PREF##Documentos d LEFT OUTER JOIN ##PREF##TiposDocumento td ON d.IDTIPODOC=td.ID) WHERE td.SIMBOLO='PD' AND d.OP1=1" objname="Documentos" updateobj="Documentos" progid="ASData.CASBasicDataObj" notify="true" notify_counter="false" notify_coll="ParteDiario" alternate-counter="true" notify_title="Entregas Avisos"> <group name="General" id="1"></group> <prop name="ID" group="1" visible="7" type="N" fieldsize="5"></prop> </coll> Image Content CONTENT IN IMAGE MODE. With this content all the data will be displayed as an image, and the user, in certain coordinates of it, will be entitled to set marks. By making a click in that mark, it will show the data relative to it, it would be like giving a row of a regular content. We must keep in mind that the example is to display a vehicle in a first image, and if we press any place of it, that could be a wheel, a glass or a door, they come up some types of damages that such part of the vehicle may have. TWO CONTENT IN A HEADING COLL. The first one is the type-image content, that has the attributes: viewmode: TO INDICATE THAT THE CONTENT IS SEEN IN IMAGE MODE imgbk: IT IS SAID THE IMAGE DISPLAYED The other content is the one that is put below and according the place where the image content is marked, the relative data will come up. <prop name="MAP_KK31-" title="Tarea Verificar. Daños" labelwidth="23" bgcolor="#CC3333" group="3" visible="0" fieldsize="8" size="8" type="TL" labelshadow="false" forecolor="#FFFFFF"/> <prop name="@PLANTILLA1" group="3" visible="1" type="Z" contents="Plantilla1" viewmode="picturemap" imgbk="##FLD_MAP_IMGPLANTILLA1##" bgcolor="#FFFFFF" lines="7" onchange="Refresh" mask="2" height="40%"/> <contents name="Plantilla1" src="Plantilla1" group="3" filter="t1.IDDOCPLANTILLA=##FLD_MAP_IDPLANTILLA1##" macros="##MACRO1##(##FLD_TAREAID##)" mask="2" bgcolor="#FFFFFF"></contents> <button name="AntesVeh" group="3" caption="<< >>" visible="true" labelwidth="12" lmargin="9" onchange="Refresh" method="ExecuteNode (antesveh)" labelfont-bold="true" bgcolor="#FFFFFF" text-bgcolor-disabled="#FFFFFF"/> <prop name="MAP_PLANTILLA" title="Vista:" labelwidth="0" type="T" size="150" locked="true" locking="true" newline="false" lmargin="1" showinline="true" linkedto="MAP_IDPLANTILLA1" linkedfield="DESCRIPCION" fieldsize="14" visible="0" group="3" onchange="Refresh255" labelshadow="false" forecolor="#CC3333" bgcolor="#FFFFFF" text-border-top="false" text-border-bottom="false" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <button name="DespuesVeh" group="3" caption=">>" visible="false" labelwidth="4" newline="false" lmargin="1" onchange="Refresh" method="ExecuteNode (despuesveh)" labelfont-bold="true" bgcolor="#FFFFFF" text-bgcolor-disabled="#FFFFFF"/> <prop name="@PDANOS1" group="3" visible="1" type="Z" contents="Danos1" lines="7" onchange="Refresh" mask="2" height="45%"/> <contents name="Danos1" src="Danos1" group="3" filter="t1.SITUACION=##FLD_MAP_SITUACION##" macros="##MACRO1##(##FLD_TAREAID##)" mask="2"></contents> <!-- COLL QUE ES EL CONTENT DE IMAGEN. TIENE QUE TENER 4 CAMPOS QUE TENDRAN LOS ATRIBUTOS PARA PINTAR LA MARCA EN EL DIBUJO QUE SE MUESTRA xcoord="true": COORDENADA X ycoord="true": COORDENADA Y circle-radius="true": PARA INDICAR EL RADIO DEL CIRCULO DE LA MARCA icon-mark="true": ICONO DE LA MARCA A PONER --> <coll name="Plantilla1" title="Plantilla1" sql="SELECT t1.ID,t1.XCOORD,t1.YCOORD, t1.RADIO,t1.SITUACION,t1.ROWID AS MAP_ROWID, t2.ID AS MAP_IDMPLANTILLA,t2.CONTADOR AS MAP_CONTADOR, CASE WHEN t2.CONTADOR>0 THEN t1.ICONMARK ELSE '' END AS ICONMARK FROM ##PREF##detplantilla t1 LEFT OUTER JOIN ##PREF##marcaplantilla t2 ON t1.ID=t2.IDDETPLANTILLA AND t2.TAREAID=##MACRO1##" objname="detplantilla" updateobj="detplantilla" progid="ASData.CasBasicDataObj" fontsize="8" editmask="2"> <!-- PESTAÑAS --> <group name="Puntos" id="1"></group> <!-- CAMPOS VISIBLES --> <macro name="##MACRO1##" value="0" default="true"/> <!-- --> <prop name="XCOORD" title="X COORD" xcoord="true" labelwidth="6" type="N" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="YCOORD" title="Y COORD" ycoord="true" labelwidth="6" type="N" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="RADIO" title="RADIO" circle-radius="true" labelwidth="6" type="N" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="SITUACION" title="SITUACION" labelwidth="6" type="N" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="ICONMARK" title="" icon-mark="true" labelwidth="6" type="T" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="MAP_IDMPLANTILLA" labelwidth="6" type="N" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="MAP_CONTADOR" labelwidth="6" type="N" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <prop name="MAP_ROWID" labelwidth="6" type="T" size="15" locked="true" locking="true" fieldsize="8" visible="7" group="1" labelshadow="false" forecolor="#CC3333" bgcolor="#CC3333" text-border-top="false" text-border-bottom="true" text-border-left="false" text-border-right="false" labelfont-bold="true" labelbox="false" labelfontsize="10" textfontsize="10" fontsize="10" text-bgcolor-disabled="#FFFFFF"/> <selecteditem onchange="Refresh255"> <action name="runscript"> <script language="VBScript"> 'DATOS DE LA PRIMERA PESTANHA this.ownerCollection.ownerObject("MAP_SITUACION")=This("SITUACION") this.ownerCollection.ownerObject("MAP_IDDETP1")=This("ID") this.ownerCollection.ownerObject("MAP_IDMP1")=This("MAP_IDMPLANTILLA") this.ownerCollection.ownerObject("MAP_CONP1")=This("MAP_CONTADOR") this.ownerCollection.ownerObject("MAP_DETIDP1")=This("MAP_ROWID") //appdata.failwithmessage -666,"" YA NO ES NECESARIO!!! </script> </action> </selecteditem> </coll> Creating a Record with Script CREATING A NEW RECORD WITH AN SCRIPT. The script can be executed in a create, insert, delete, button… at any place. <action name="histor" type="runscript"> <script language="VBScript"> 'Dimensionamos las variables Dim coll,det 'Cogemos en que coleccion se va a crear el nuevo objeto, con lo que tomara todas las caracteristicas del mismo, ' ejecutandose el create si lo tuviera. Set coll =AppData.GetCollection("ColeccionEnLaQueSeCreaElRegistro") 'Creamos el objeto set det = coll.CreateObject 'Lo añadimos a la coll, lanzando el create del mismo coll.AddItem Empty,det 'Añado los valores a los distintos campos det("CAMPONUMERICO")=5 det("CAMPOTEXTO")="VALOR DEL CAMPO" det("CAMPOFECHA")=now() 'Salvo el objeto det.Save 'Liberamos variables. set coll.clear Set coll=nothing Set det=nothing </script> </action> Putting value to a Global Variable <action name="runscript"> <script language="VBScript"> appdata.CurrentEnterprise.Variables("NoAvisar")=0 </script> </action> Information Queue Device COLECTION THAT DISPLAYS THE AMOUNT OF THE MISSING DATA TO SENT. This collection can be as complicated as we want to, even by putting Join with other tables, to say which table the data to send are missing, from the mobile device to the central. The MASTER_REPLICA_QUEUE table, only can be used to see data, never to write directly on it, since it is a system table, with which the data will be sent from the mobile device to the central server. <coll name="InformacionQueue" title="la informacion queue" sql="SELECT COUNT(ID) AS MAP_CUENTA FROM master_replica_queue" objname="master_replica_queue" updateobj="master_replica_queue" progid="ASData.CASBasicDataObj" forprint="false" editwidth="75" editheight="76" autorefresh="true"> <group name="General" id="1"/> <prop name="MAP_CUENTA" visible="7" group="1" type="N" fieldsize="20" labelwidth="8" size="30">DATOS PARA ENVIAR</prop> </coll>