Question

Implement a “Maximum number of daily periodical editions” integer system setting, set its value to 5 (five).

Any one guide me how i can implement it by business rules or business process ? any other method ???

Perform verification whenever a user adds or modifies a daily periodical edition. If the total number of active daily editions exceeds the system setting value (see item 5), saving a record should not be permitted. Instead, bpm’online should display a message informing that the production capacity is limited and no more than “N” daily editions can be active at a time, where “N” is the system setting value. 

Implementation method: handlers in the JavaScript code of the edit page with applying the client ESQ and validation mechanism

Like

4 comments

Hello Muhammad!

The way how to achieve this: create your own object where you will store information about editions of objects for each user. After that, you should create replacing client module where implement methods that will get info about editions of object from the database via esq and compare it with system setting "Maximum number of daily periodical editions".
Please note, that system setting will be the same for every user.

Best regards,
Alex

Alex_Tim,

Thanks Alex I have created Object where I can add or edit the records in Periodical Edition and also created system settings " Maximum number of daily periodical editions " default value is 5 . but replacing client module is not clear me can u elaborate it ?

Thanks

Muhammad Attique,

Hello,

You should create replacing client module exactly for the page that you want not to be accessible for editing regarding to the system setting. The idea is to compare system setting when page opens in "onEntityInitialized" method. Then you may made controls read-only or just prohibit saving of the record.

Queries to system setting:

https://community.bpmonline.com/questions/system-settings-query-issue

Hide controls:

https://community.bpmonline.com/questions/hide-section-button-edit-page

ESQ:

https://academy.bpmonline.com/documents/technic-sdk/7-13/use-entitysche…

 

 

Create two attributes to store results from the ESQ Queries to be called outside their scope. Below code explains this

attributes: {
            "MaxPeriodicalEditions": {
        "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
        "dataValueType": Terrasoft.DataValueType.INTEGER,
        "value": "0"
    },
            "ReturnedRecords": {
        "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
        "dataValueType": Terrasoft.DataValueType.INTEGER,
        "value": "0"
    },
        },
.........
        methods: 
        {
            //Calling the Validation Method on Active Field in Periodical Editions Section Records
            setValidationConfig: function() {
            this.callParent(arguments);
            this.addColumnValidator("UsrActive", this.ActiveEditionsValidator);
            },
/*Validation Program whenever a user adds or modifies a daily periodical edition and If the total
number of active daily editions exceeds the system setting value, saving a
record is not permitted.*/
 
            ActiveEditionsValidator: function() {
 
                //Fetch The Maximum Number Of Daily Periodical Editions System Setting
                
                Terrasoft.SysSettings.querySysSettingsItem("UsrMaximumNumberOfDailyPeriodicalEditions",
                function(result) {
                    this.set("MaxPeriodicalEditions",result);
                }, this);
                
                //Store the system setting in a local variable
                var mySetting= this.get("MaxPeriodicalEditions");
                
                //Variable to store the Count of Active Records
                 var esqresult = "";
                 
                 //ESQ Selection of the parent Object
                var esq = Ext.create("Terrasoft.EntitySchemaQuery", 
                {rootSchemaName: "UsrPeriodicalEditions"});
                
                //Addition of Active and Publication Frequency Columns to Query
                esq.addColumn("UsrActive", "ActiveRecords");
                esq.addColumn("UsrLookup1.Name","PublicationFrequency");
                
                //Filteration to only include the count of records where the record is active and Publication Frequency is Daily
                var esqFirstFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrActive", "true");
                var esqSecondFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
                "UsrLookup1.Name", "Daily");
                
                //Addition of Filters to the query
                esq.filters.add("esqFirstFilter", esqFirstFilter);
                esq.filters.add("esqSecondFilter", esqSecondFilter);
                
                //Aggregation to get the Count of resulting Query
                esq.addAggregationSchemaColumn("UsrActive", Terrasoft.AggregationType.COUNT, 
                "ActiveRecords1", Terrasoft.AggregationEvalType.All);
                
                // Get the entire esq result colelction
                esq.getEntityCollection(function (result) {
                    if (!result.success) {
                    // In case the query doesn't yield any results specially when there is no such record
                    return;
                    }
                    
                    //Store the Count of Filtered Records to a variabble
                    esqresult =result.collection.getByIndex(0).get("ActiveRecords1");
                    
                    //Set the value of Attribute to access it globally
                    this.set("ReturnedRecords",esqresult);
},this);
 
                    //Variable to store the Validation Message
                    var invalidMessage = "";
                    
                    //Local Variable to store the Count of Filtered Records
                    var comparison = this.get("ReturnedRecords");
                    
                    //Comparison to check only if the count of active Daily Edition Records is greater than system setting
                    if(comparison>=mySetting && this.get("UsrLookup1").displayValue==="Daily" && this.get("UsrActive")===true)
                    {
                     // Assign the Validation Error Message to our local variable
                    invalidMessage = this.get("Resources.Strings.ActiveDailyEditionsValidationMessage");
                }
                 // If the validation is successful, empty strings are returned to the object and no action taken
                return {
                    invalidMessage: invalidMessage
                };
            }
        },

 

Log in or register to comment