ObjectGears Help

Forum   ObjectGears (Version:

Module MultiEdit

This module contains webpart for a mass record editing. By means of a simple scripting you can edit more records at one time and accelerate some operations in this way.


You will pass list of records, to which the user has access rights, to the webpart by means of scripting. Webpart will display them in form of rows where each field can be edited. User can also delete records or create new ones.

There is information about parent record, if it exists, in the upper part of the webpart - e.g. invoice record, where user can change invoice items.

Webpart does not ensure access right control. This has to be managed by means of scripts by initialization. It is necessary to read only those records that the user can edit and save only what has to be saved.


Property Description
Enable new records Property for creation of new records. When enabled user can create a new record.
Enable to delete records Property for deletion of records. When enabled user can delete records.
Script for initialization Script is executed at display of the page with webpart.
Script for reading records Script is executed reading records for editing.
Script for displaying records Script is executed for ech record before its display on the page.
Script for initialization of a new record Script is executed at at new record creation.
Script for saving records Script is executed at saving all the records.
Script for record deletion Script is executed at record deletion.

Script parameters for initialization

Verify in the script whether user can edit anything. Then read the class that will be edited and columns that shall be displayed in the webpart.

OGInit - object for web initialization.

Properties of object OGInit.


Vlastnost Popis
bool NewAsPerson Příznak zda pro nový záznam se má nejprve vybrat uživatel. Při nezaškrtnutí je rovnou přidán nový záznam.
ClassDef ClassDef Třída, jejíž záznamy má uživatel editovat.
ColumnClassDefList Columns Seznam sloupců ze třídy, které se mají uživateli zobrazit pro editaci.
string ErrorMessage Při zadání chybového hlášení bude uživatel přesměrován na chybovou stránku. Vlastnost použijte např. při neoprávněném přístupu uživatele na stránku.
string LinkNavigation Text pro drobečkovou navigaci. Formát je stejný jako u metody OGForm.SetLinkNavigation.
string BackUrl URL pro tlačítko Zpět.

Script parameters for reading list of records

In the script read the records, that the user shall see and edit.

OGInit - object form initialization. It contains class, for which the records shall be read.

Return the list of records by means of return.

Script parameters for record display

Script is executed for each record before it is displayed in the page.

OGRow - configuration for currently displayed record.
OGClassDef - class to which the record belongs.
OGDataRow - record that shall be displayed.

Properties of the object OGRow

Name Description
bool EnableDelete Indication for enabling/disabling record deletion.
bool EnableSave Indication for enabling/disabling record saving.
ColumnMultiEdit this[string code] Function returns column accoridng to the given code.
ColumnMultiEdit this[int columnId] Function returns column accoridng to the given id.

Vlastnosti objektu ColumnMultiEdit

Name Decription
ColumnClassDef Column Determination of column for which the setting applies.
bool ReadOnly Indication whether column shall be displayed in readonly mode.
bool Visible Indication whether column shall be displayed.

Script parameters for a new record

The script is executed after clicking on button New.

OGNewDataRow - DataRow for a new record.
OGActualMessage - object for setting error message.
OGDataRows - list of records that are already in the multi-edit webpart. You can use it for check whether user can add a new record.
OGPerson - selected new user.

When an errror message is set by means of method OGActualMessage.SetError, you can cancel the creation of a new record. An error message is then displayed to the user.


If there is property NewAsPerson checked in the webpart settings, there is a person, that the user selected at creation of a ne record, passed in the parameter OGPerson. You can read this property in the script and check, whether a record can be created with selected user. Insert the user into OGNewDataRow if needed.

Script parameters for storing records

OGDataRows - list of records that shall be saved. The list contains only records that were changed by the user. At the same timese it contains only records that are not readonly.

The saving itself will be secured by the webpart. You just check that everything is properly defined. If you find an error, throw an exception (OG.Throw) and saving will be cancelled.

Script parameters for record deletion

OGDataRowId - Id of a deleted record

If you throw an exception (OG.Throw) in the script, saving will be cancelled.

Scripts on page

You can set url for button Back and crumbread navigation on page by means of following. You will read the values from the webpart MultiEdit with code multi-edit. You have to define these values before in the initialization script of the webpart.

function OnPreRender()
    var m = OGWebParts['multi-edit'];

    OGForm.SetLinkNavigation( m.LinkNavigation);

    var b = OGForm.GetControl('backToolbarButton');
    b.Visible = true;
    b.NavigateUrl = m.BackUrl;

Script examples

Below scripts are from capacity planning model, where users can edit project plan capacities.

Script for initialization

var cl = OG.ClassDef.GetByCode( 'it', 'project_year_requested_resources_monthly');
OGInit.ClassDef = cl;
OGInit.NewAsPerson = true;

var zpid = OG.QueryString.GetInt('drId');
if ( zpid != null)
    var clPR = OG.ClassDef.GetByCode( 'it', 'project_resources');
    var f = OG.DataRow.GetDataRowFilter( clPR.Id, zpid);
    var r = OG.ClassDef.HaveUserRightByClassDef( clPR.Id, OG.ClassDef.ClassDefRoleOperation_Update);
    if ( r == OG.ClassDef.RoleRight_RoleWithOrgStructure)
        f.Filter_AplyOrgStructureForOperation = OG.ClassDef.ClassDefRoleOperation_Update;
    var drl = OG.DataRow.GetDataByFilter(f);

    if ( drl != null && drl.Count == 1)
        var dr = drl[0];
        var drp = dr.GetDR('project');
        var i = OGInit.Detail.CreateItem(clPR.Columns['project'].Name, drp.ShortDescription);
        i.ValueLink = drp.DetailUrl;

        var i1 = OGInit.Detail.CreateItem(clPR.Columns['year'].Name, dr['year']);
        var i2 = OGInit.Detail.CreateItem(clPR.Columns['amount'].Name, dr['amount']);
        OGInit.Detail.AddRow(i1, i2);

        var col = clPR.Columns['cost_type'];
        var i1 = OGInit.Detail.CreateItem(clPR.Columns['cost_type'].Name, dr.GetColumnDataAsString2( col.Id, col.ColumnType));
        var i2 = OGInit.Detail.CreateItem(clPR.Columns['accounting_amount'].Name, dr['accounting_amount']);
        OGInit.Detail.AddRow(i1, i2);

        var col = clPR.Columns['accounting_currency'];
        var i = OGInit.Detail.CreateItem(clPR.Columns['accounting_currency'].Name, dr.GetColumnDataAsString2( col.Id, col.ColumnType));

        OGInit.LinkNavigation = clPR.Model.Name + '|ModelInfo.aspx?Id=' + clPR.Model.Id + '>' + clPR .Name + '|' + dr.ListUrl + '>Záznam ID ' + dr.Id + '|' + dr.DetailUrl + '>Multi edit|WebContentPage.aspx' + OG.QueryString.Query;
        OGInit.BackUrl = dr.DetailUrl;
        OGInit.ErrorMessage = 'Nemáte právo na úpravu zdrojů.';
    OGInit.ErrorMessage = 'Není zadán zdroj pro úpravu.';

Script for reading records

var zpid = OG.QueryString.GetInt('drId');
if ( zpid != null)
    var col = OGInit.ClassDef.Columns['project_resources'];

    var f = OG.DataRow.GetDataRowFilter( OGInit.ClassDef.Id);
    f.Filter_OnlyActive = true;
    f.SetColumnData( col.Id, zpid);
    var drl = OG.DataRow.GetDataByFilter(f);

    var cl = OG.ClassDef.GetByCode( OGInit.ClassDef.Model.Id, 'requested_resource_status');
    var planStatus = OG.DataRow.GetDataRowByCode(null, cl, 'plan');
    var approvedStatus = OG.DataRow.GetDataRowByCode(null, cl, 'approved');
    var forapproveStatus = OG.DataRow.GetDataRowByCode(null, cl, 'for_approve');

    var usIds = ',';
    for( var i = 0; i < drl.Count; ++i)
        var statusId = drl[i]['requested_resource_status'];
        if ( statusId == planStatus.Id || statusId == forapproveStatus.Id)
            usIds += drl[i]['resource'].Id + ',';
    OG.SetItem('users1', usIds);

    return drl;

return null;

Script for display of records

OGRow['resource'].ReadOnly = true;
OGRow['requested_resource_status'].ReadOnly = true;

var usIds = OG.GetItem('users1');
if ( usIds != null)
   var cl = OG.ClassDef.GetByCode( OGClassDef.Model.Id, 'requested_resource_status');
   var approvedStatus = OG.DataRow.GetDataRowByCode(null, cl, 'approved');

   if ( OGDataRow['requested_resource_status'] == approvedStatus.Id && usIds.indexOf( ',' + OGDataRow['resource'].Id + ',') >= 0)
      //var planStatus = OG.DataRow.GetDataRowByCode(null, cl, 'plan');
      var ro = true;   //!( OGDataRow['requested_resource_status'] == planStatus.Id);
      OGRow['m01'].ReadOnly = ro;
      OGRow['m02'].ReadOnly = ro;
      OGRow['m03'].ReadOnly = ro;
      OGRow['m04'].ReadOnly = ro;
      OGRow['m05'].ReadOnly = ro;
      OGRow['m06'].ReadOnly = ro;
      OGRow['m07'].ReadOnly = ro;
      OGRow['m08'].ReadOnly = ro;
      OGRow['m09'].ReadOnly = ro;
      OGRow['m10'].ReadOnly = ro;
      OGRow['m11'].ReadOnly = ro;
      OGRow['m12'].ReadOnly = ro;

Script for a new record

var cl1 = OG.ClassDef.GetById( OGNewDataRow.ParentId);
var cl = OG.ClassDef.GetByCode( cl1.Model.Id, 'requested_resource_status');
var planStatus = OG.DataRow.GetDataRowByCode(null, cl, 'plan');

OGNewDataRow['requested_resource_status'] = planStatus .Id;
OGNewDataRow['resource'] = OGPerson.ToPersonInfo();
OGNewDataRow['project_resources'] = OG.QueryString.GetInt('drId');

if ( OGPerson != null && OGDataRows != null)
    for( var i = 0; i < OGDataRows.Count; ++i)
        var p = OGDataRows[i]['resource'];
        if ( p != null && p.Id == OGPerson.Id)
            OGActualMessage.SetError('This user is already selected. Please select another user.');

Example of appearance

There are values from a parent record in the upper part of the webpart. Properties and values are populated by a script for initialization.

Then there are buttons for a new record and saving of all the records.

The last part are records for editing. In the below example there are two columns in read-only mode. Other columns in a row can be edited.


Webpart configuration example. Each script has its own text field.

This website is using cookies files to provide services and analyse visits. You agree with that by using this website.     Further information