Article

Adding lookup with edit page

Case description:

We want to add lookup with edit page.

This lookup looks like this:

Edit page:

How to do it:

1) Create section schema with parent object “Base lookup configuration section” and add method “addRecord” if you want to open edit page when you click on “New” button.

Example:

For example I created object schema “Automobile” with columns: Manufacturer (Text), Brand (Text), Date of issue (Date), Country of issue (Lookup: Country):

After that I created new Schema of the Section View Model for lookup and set parent object “Base lookup configuration section”:

And added next code to “Source code”:

define("GlbAutomobileLookupSectionV2", ["ConfigurationEnums", "ConfigurationGrid", "ConfigurationGridGenerator",
    "ConfigurationGridUtilities"],
    function(ConfigurationEnums) {
        return {
            entitySchemaName: "GlbAutomobile",
            attributes: {},
            diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
            messages: {},
            methods: {
                addRecord: function(typeColumnValue) {
                    if (!typeColumnValue) {
                        if (this.get("EditPages").getCount() > 1) {
                            return false;
                        }
                        var tag = this.get("AddRecordButtonTag");
                        typeColumnValue = tag || this.Terrasoft.GUID_EMPTY;
                    }
                    var schemaName = this.getEditPageSchemaName(typeColumnValue);
                    if (!schemaName) {
                        return;
                    }
                    this.openCardInChain({
                        schemaName: schemaName,
                        operation: ConfigurationEnums.CardStateV2.ADD,
                        moduleId: this.getChainCardModuleSandboxId(typeColumnValue)
                    });
                }
            }
        };
    });

If you don’t want open edit page when you click on “New” button then remove method “addRecord”:

define("GlbAutomobileLookupSectionV2", ["ConfigurationEnums", "ConfigurationGrid", "ConfigurationGridGenerator",
    "ConfigurationGridUtilities"],
    function(ConfigurationEnums) {
        return {
            entitySchemaName: "GlbAutomobile",
            attributes: {},
            diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
            messages: {},
            methods: {}
        };
    });

Saved schema.

2) Create edit page schema with parent object “Base lookup page”. And add your controls.

Example:

Created new Schema of the Edit Page View Model for lookup and set parent object “Base lookup page”

And added next code to “Source code” with columns of my object:

define("GlbAutomobileLookupEditPageV2", [],
    function() {
        return {
            entitySchemaName: "GlbAutomobile",
            details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
            attributes: {},
            methods: {},
            rules: {},
            diff: /**SCHEMA_DIFF*/[
                {
                    "operation": "merge",
                    "name": "Name",
                    "parentName": "GeneralInfoControlGroup",
                    "propertyName": "items",
                    "values": {
                        "layout": {
                            "colSpan": 12,
                            "column": 0,
                            "row": 0
                        }
                    }
                },
                {
                    "operation": "insert",
                    "name": "GlbManufacturer",
                    "values": {
                        "layout": {
                            "colSpan": 12,
                            "rowSpan": 1,
                            "column": 0,
                            "row": 2,
                            "layoutName": "GeneralInfoControlGroup"
                        },
                        "bindTo": "GlbManufacturer"
                    },
                    "parentName": "GeneralInfoControlGroup",
                    "propertyName": "items",
                    "index": 1
                },
                {
                    "operation": "insert",
                    "name": "GlbBrand",
                    "values": {
                        "layout": {
                            "colSpan": 12,
                            "rowSpan": 1,
                            "column": 0,
                            "row": 3,
                            "layoutName": "GeneralInfoControlGroup"
                        },
                        "bindTo": "GlbBrand"
                    },
                    "parentName": "GeneralInfoControlGroup",
                    "propertyName": "items",
                    "index": 1
                },
                {
                    "operation": "insert",
                    "name": "GlbDateOfIssue",
                    "values": {
                        "layout": {
                            "colSpan": 12,
                            "rowSpan": 1,
                            "column": 0,
                            "row": 4,
                            "layoutName": "GeneralInfoControlGroup"
                        },
                        "bindTo": "GlbDateOfIssue"
                    },
                    "parentName": "GeneralInfoControlGroup",
                    "propertyName": "items",
                    "index": 1
                },
                {
                    "operation": "insert",
                    "name": "GlbCountryIssue",
                    "values": {
                        "layout": {
                            "colSpan": 12,
                            "rowSpan": 1,
                            "column": 0,
                            "row": 5,
                            "layoutName": "GeneralInfoControlGroup"
                        },
                        "bindTo": "GlbCountryIssue"
                    },
                    "parentName": "GeneralInfoControlGroup",
                    "propertyName": "items",
                    "index": 1
                }
            ]/**SCHEMA_DIFF*/
        };
    });

Saved schema.

3) Register edit page in your database by SQL script.

Example:

DECLARE
-- Name of edit page schema.
@CardSchemaName NCHAR(100) = 'GlbAutomobileLookupEditPageV2',
-- Name of object schema.
@EntitySchemaName NCHAR(100) = 'GlbAutomobile',
-- Caption of your page.
@PageCaption NCHAR(100) = 'Automobiles lookup pagee',
-- Empty string.
@Blank NCHAR(100) = ''
 
-- Adding record in table SysModuleEntity.
INSERT INTO SysModuleEntity(
    ProcessListeners,
    SysEntitySchemaUId
)
VALUES(
    0,
    (SELECT TOP 1 UId
    FROM SysSchema
    WHERE Name = @EntitySchemaName
    )
)
 
-- Adding record in table SysModuleEdit
INSERT INTO SysModuleEdit(
    SysModuleEntityId,
    UseModuleDetails,
    Position,
    HelpContextId,
    ProcessListeners,
    CardSchemaUId,
    ActionKindCaption,
    ActionKindName,
    PageCaption
)
VALUES (
    (SELECT TOP 1 Id
    FROM SysModuleEntity
    WHERE SysEntitySchemaUId = (
        SELECT TOP 1 UId
        FROM SysSchema
        WHERE Name = @EntitySchemaName
        )
    ),
    1,
    0,
    @Blank,
    0,
    (SELECT TOP 1 UId
     FROM SysSchema
     WHERE name = @CardSchemaName
    ),
    @Blank,
    @Blank,
    @PageCaption
)

And add record in Localizable string table. For it you should know your RecordId by special query

Example:

I need add localizable string in table “SysModuleEditLcz” by next SQL script:

DECLARE
-- Caption of your page.
@PageCaption NCHAR(100) = 'Automobiles lookup pagee'
 
-- SysCultureId - Id for en-US from table SysCulture
INSERT INTO SysModuleEditLcz(Id, ModifiedOn, RecordId, SysCultureId, ActionKindCaption, PageCaption)
    VALUES(NEWID(), GETUTCDATE(), 'RecordId you can get by script below', 'A5420246-0A8E-E111-84A3-00155D054C03', 'Add', @PageCaption)

Here I need “RecordId” and use next script to know it:

SELECT sme.Id, sme.CreatedOn
                --SELECT DISTINCT sme.Id, sme.CreatedOn
                FROM SysModuleEdit as sme
                    JOIN SysModuleEntity as sment on sment.Id = sme.SysModuleEntityId
                    JOIN SysSchema as sse on sse.UId = sment.SysEntitySchemaUId
                    JOIN SysSchema as ss on ss.UId = sme.CardSchemaUId
                WHERE sse.Name = 'GlbAutomobile'
                    AND ss.Name = 'GlbAutomobileLookupEditPageV2'
                ORDER BY sme.CreatedOn DESC

And i have got RecordId:

After that I execute script above with RecordId:

4) Register lookup in system and choose your section in "List page" field.

Example:

As result, I have Lookup with Edit Page:

When I click “Add”, it opens my edit page (Because I added method “addRecord” in schema “GlbAutomobileLookupSectionV2”. If you don’t want it – remove this method):

Like 1

Like

Share

1 comments

Tatiana Rogova, this article is really helpful. It would be of more useful if the scripts are shared for other db as well - PostgreSQL . Kindly consider this. 

Show all comments