1. Webpart Script

    Artikel: AN0001971Aktualisiert: 07.10.2018
    Die vorgegebene Sprachenversion vom Artikeltext wird angezeigt, weil es kein Text von der ausgewählten Sprache und Version gibt.

    This webpart is used for two purposes that are met by means of scripting:

    • Create a form (that can be edited) without any underlying class. This can beused for entering values, based on which an action is performed. E.g. you create records in other classes, start a workflow etc.
    • Create html that is pasted into a page. It is a very simple way of creating a report - displaying data from other classes by html. You can read the data directly from database, module procedure or you create html by means means of scripts.

    You have this objects for scripting:

    Name Description
    OG Basic object for work with scripts.
    OGForm Object for work with page content.
    OGContentPage Page object.
    OGModel Model, to which the page belongs. If the page is not assigned to any model, this value is NULL.
    OGWebPart Object of the webpart Script.
    OGWebParts List of webparts on page.

    You can configure several properties in the webpart settings:

    Setting Description
    Script In this script you can create definition of own form or html. You can define function OnLoad and OnPreRender. Both correspond to events from ASP.NET.
    Script events This script contains functions for events, e.g. click on a button on toolbar.

    Here you can enter url link to a file with styles. You have to save this file on server.

    You can use here you own styles that will be pasted into the page with webpart.


    Here you can enter url link to the file with javascript. You have to save this file on server.

    You can use here also your own javascript that will be pasted into the page with webpart.

    There can be more Script webparts inserted into one page. The order of script runs is then defined by the zone order (each zone has its unique number) and within the zone by the webpart order in the zone.

    Example of events OnLoad and OnPrerender

    function OnLoad()

    function OnPreRender()

    Example of an event definition

    The event can be defined only for clicking on a toolbar button. The name of the event consists of the button ID and text _Click.

    function bSave_Click()
       /* displaying various informatory messages */
       OGForm.SetInfo( 'Something is happening.');
       OGForm.SetError( 'There is an error.');
       OGForm.SetSuccess( 'Data were saved.');
       OG.Log.Write('Button save.');

       /* reading data from a text field */
       var tb = OGForm.GetControl( 't1');
       OGForm.SetInfo( 'Code: ' + tb.Text);

    Example of a style definition

       font-size: 10px;

    Example of javascript

    function MyFunction()

    Work with webparts on page

    Both webpart and page can work with other webparts. Use the property OGWebParts to access the other webparts. You can refer to particular webparts by the index in collection or by the webpart code.

    var wp = OGWebParts[1];

    var wp = OGWebParts['webpart_code'];

    Takeover of values from URL

    You can react on values provided in URL within a script. You can process the values and fill in controls with them.

    The values shall be taken over only at the first display of the page (when there is no postback). Use function IsPostback to identify these situations. After that fill in the data into controls by the method SetData.

    The following example takes over value from the variable data at the first page display from the URL and inserts the value into the control t2.

    if ( !OGForm.Page.IsPostback)
       t2.SetData( OG.QueryString.GetString('data'));