You are viewing limited content. For full access, please sign in.

Question

Question

filling in table with stored procedure and empty table handling

asked on December 15, 2023 Show version history

To start, my environment is on prem Laserfiche Forms Professional Version 11.0.2307.40556.  I am using the new layout designer for development.

The issue I'm trying to solve...

I've been using a stored procedure to dynamically establish a customized set of approvers based on organizational hierarchy.  Essentially pick whatever using a database lookup,  feed a number of fields with organizational data, and use that information to fill the stored procedures parameters, which brings back a table of the necessary approvals. The thing is the stored proc fires a lot (once at the beginning and once each change event), and overwhelms form, so I built a calculated field that tests to see if all the data needed is there and sends an Ignore parameter that returns the table with no rows, this results in a table with one blank row on the Forms side.

This works well excepting for sometimes the initial load, the timing gets befuddled and sometimes brings back and earlier request after the last change event's request.  Since he empty table always results in a blank row which is not ideal.  When the timing gets out of sync it'll append that blank row to the real  table, and sometimes when this happens, it sometimes throws a console error, something about .split() which stops the form from being able to submit.

I would love to be able to have fine control the timing of database lookups, but until that functionality is added, I was wondering if anyone out there has a better way, best practices or recommendations  of getting a stored procedure to produce a 100% reliable table using field variables in the forms layout designer. Or recommendations on handling or removing the blank rows, everything I try seems to not work out.  Overall this process works beautifully about 90% of the time and my users are generally happy with it, I just would be thrilled to get to that elusive 100%.

 Any help or suggestions are much appreciated.

LFFEmptySet.JPG
LFFEmptySet.JPG (36.14 KB)
0 0

Replies

replied on December 18, 2023 Show version history

Are you using any custom JavaScript on this form? If so, it would help to see that code to try and understand what else may be affecting things.

I've never had any issues like this with the reliability of lookup results, so it seems like something else might be going on in your situation.

Have you tried adding a default value to your calculation field? It may be that the lookup runs before the calculation so it doesn't have the ignore parameter.

There used to be a workaround in the classic designer where you could turn off autofill, which added a button to trigger the lookup manually. Then you could hide the button and trigger it via JavaScript, but I don't think that's possible with the modern designer.

 

You said this doesn't always happen so the table settings seem unlikely to be a factor, but also double check the how the table is configured to handle rows.

Again, it seems unlikely based on some of the details you provided, but if the table was set to append a minimum of 1 row it could cause behavior like this.

 

0 0
replied on December 18, 2023

I'm not currently using any javascript in this form.   I set up my tables using the following settings which can bring in multiple rows of records without allowing users to add rows. I generally disable the visible fields as well so the table is for all intensive purposes read only.

TableSetting.JPG
TableSetting.JPG (74.15 KB)
0 0
replied on December 30, 2023

Hi Rebekah, 

I am working on something similar to this right now (I think it's similar). I just want to get a better handle on how you get the criteria to determine who the approvers are. Could you give us some more info on how approvers are populated?

Without knowing all of the details it just sounds like you should be able to do a table lookup (SELECT) but I think there may be some more complexity. 

0 0
replied on January 2, 2024

It's essentially setting up a field to calculate or default to your approval settings, and a stored proc with a standardized table, using select statements to fill in the rows one by one.  I built out sql views that are specifically structured to answer the questions I'm asking and fill in the data I need. For example, the department head where clause look like WHERE IsDepartmentHead='Yes' and Department=@Dept and returns the @@ApprovalTable fields.   Here's some simplified psuedo code, that hopefully demonstrates the general concept.

CREATE PROCEDURE [Create_ApprovalTable]
    @EmployeeNum   NVARCHAR(MAX),
    @ApprovalLevel NVARCHAR(MAX) = 'IGNORE', --Employee, Supervisor, etc. formatted "Supervisor/Employee"
    @Dept          NVARCHAR(MAX) = ''
AS
    SET NOCOUNT ON;
    DECLARE @@ApprovalTable TABLE
        (
            RN                   INT,
            ApprovalType         NVARCHAR(MAX),
            Approval_DisplayName NVARCHAR(MAX),
            Approval_User        NVARCHAR(MAX),
            Approval_EmployeeNum NVARCHAR(MAX),
            Approval_NameNum     NVARCHAR(MAX)
        );

    DECLARE
        @OutEmpNum NVARCHAR(MAX),
        @OutDN     NVARCHAR(MAX),
        @OutSAM    NVARCHAR(MAX),
        @OutNN     NVARCHAR(MAX),
        @RwCnt     INT          = 1,
        @TempType  NVARCHAR(MAX);


    INSERT INTO @@ApprovalTable
        (
            RN,
            ApprovalType
        )
                SELECT
                    ROW_NUMBER() OVER (ORDER BY
                                           (
                                               SELECT
                                                   NULL
                                           )
                                      ) RN,
                    *
                FROM
                    STRING_SPLIT(@ApprovalLevel, '/');


    WHILE @RwCnt <=
        (
            SELECT
                MAX(RN)
            FROM
                @@ApprovalTable
        )
        BEGIN
            SET @OutEmpNum = NULL;
            SET @OutDN = NULL;
            SET @OutSAM = NULL;
            SET @OutNN = NULL;
            SELECT
                @TempType = ApprovalType
            FROM
                @@ApprovalTable
            WHERE
                RN = @RwCnt;
            IF @TempType = 'Employee'
                BEGIN
                    SELECT TOP 1
                           @OutDN     = DisplayName,
                           @OutSAM    = LFAccountUserName,
                           @OutEmpNum = EmployeeNumber,
                           @OutNN     = DisplayName_Number
                    FROM
                           employeedata
                    WHERE
                           EmployeeNumber = @EmployeeNum;
                END;
            --IF's go on and on for each type supported

            UPDATE
                @@ApprovalTable
            SET
                Approval_EmployeeNum = @OutEmpNum,
                Approval_NameNum = @OutNN,
                Approval_DisplayName = @OutDN,
                Approval_User = @OutSAM
            WHERE
                RN = @RwCnt;

            SET @RwCnt = @RwCnt + 1;
        END;
    SELECT
        ApprovalType,
        ISNULL(Approval_DisplayName, '') Approval_DisplayName,
        ISNULL(Approval_User, '')        Approval_User,
        ISNULL(Approval_EmployeeNum, '') Approval_EmployeeNum,
        ISNULL(Approval_NameNum, '')     Approval_NameNum
    FROM
        @@ApprovalTable;

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.