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

Question

Question

SQL query for Form lookups

asked on November 22, 2024

Our organization uses DB lookups on a number of Forms, and to prepare for a project next year we're looking to do some discovery into which Forms have db lookups and which tables, stored procedures, and views are referenced by each. I have access to our Forms database on-prem via SSMS, but I'm having trouble guessing the schema just right for my query. Is there a resource available to explain that?


Thanks!

Megan Bermudez

0 0

Replies

replied on November 22, 2024

Take a look at this answers discussion it should help https://answers.laserfiche.com/questions/176930/Forms-Data-Source--Linked-Processes#225078

 

1 0
replied on November 22, 2024

This will combine the scripts, so it's all mapped together:

 

SELECT 
    ced.table_name, 
    cesp.stored_procedure_name, 
    cfm.form_id, 
    lr.lookup_rule_id,
    Lookups.database_display_name AS Data_Source, 
    cf_business_processes.name AS Process_Name, 
    cf_forms.name AS Form_Name
FROM 
    cf_lookup_rules lr
JOIN 
    cf_field_column_mapping cfm 
    ON cfm.mapping_id = (
        SELECT TOP 1 mapping_id 
        FROM cf_field_column_mapping 
        WHERE lookup_rule_id = lr.lookup_rule_id 
        ORDER BY mapping_id ASC
    )
LEFT JOIN 
    cf_external_dbtables ced 
    ON lr.external_datasource_id = ced.datasource_id
LEFT JOIN 
    cf_external_stored_procedures cesp 
    ON lr.external_datasource_id = cesp.datasource_id
INNER JOIN (
    SELECT DISTINCT 
        cf_lookup_rules.lookup_rule_id, 
        cf_lookup_rules.external_datasource_id, 
        cf_field_column_mapping.form_id, 
        cf_form_process_mapping.process_id, 
        cf_external_databases.database_display_name
    FROM
        cf_lookup_rules
    LEFT OUTER JOIN 
        cf_field_column_mapping
        ON cf_lookup_rules.lookup_rule_id = cf_field_column_mapping.lookup_rule_id
    INNER JOIN 
        cf_form_process_mapping
        ON cf_field_column_mapping.form_id = cf_form_process_mapping.form_id
    INNER JOIN 
        cf_external_dbtables
        ON cf_lookup_rules.external_datasource_id = cf_external_dbtables.datasource_id
    INNER JOIN 
        cf_external_databases
        ON cf_external_dbtables.database_id = cf_external_databases.database_id
    WHERE 
        cf_lookup_rules.is_disabled != '1'
        AND cf_lookup_rules.external_datasource_id IS NOT NULL
) AS Lookups
ON lr.lookup_rule_id = Lookups.lookup_rule_id
INNER JOIN 
    cf_forms
    ON Lookups.form_id = cf_forms.form_id
INNER JOIN 
    cf_bp_processes
    ON Lookups.process_id = cf_bp_processes.process_id
INNER JOIN 
    cf_business_processes
    ON cf_bp_processes.bp_id = cf_business_processes.bp_id
WHERE 
    cf_business_processes.is_deleted != '1'
    AND cf_business_processes.is_archived != '1'
ORDER BY 
    cfm.form_id ASC;

 

1 0
replied on November 22, 2024

That's perfect, thank you both!

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

Sign in to reply to this post.