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

Question

Question

How to call a lookup rule through JavaScript in Laserfiche Cloud Modern Designer

asked on November 27 Show version history

Hi, I am using Laserfiche 12 Cloud Modern Designer I would like to call a specific lookup rule (ID: 2) through JavaScript based on an input value, for this case example: Only when Field Id: 39 has 'run' as value. The Field Id :39 is a single Field.

Based on the LFForm object documentation I am using onLookupTrigger to cancel and not cancel the lookup rule. Sadly, it works only when the form is loaded. Since the lookup rule has no 'where' conditions it is triggered when the form is loaded and as the field id:39 has an empty value the lookup rule is canceled, this is ok for the business process, but after it is canceled I can't find a way to trigger it again when the field value of the field Id :39 is 'run'. 

Is there a way to call a specific lookup rule  through JavaScript in Laserfiche Cloud Modern Designer after the form has loaded

This is my code:

// Listen for changes to Field 39 and trigger the lookup rule accordingly
LFForm.onFieldChange(function() {
    let run = LFForm.getFieldValues({ fieldId: 39 });
    // Check if the field value is 'run'
    if (run === 'run') {
        // Allow the lookup rule to execute
        LFForm.onLookupTrigger(function() {
            return { cancelLookup: false }; // Do not cancel the lookup rule
        }, { lookupRuleId: 2 });
    } else {
        // Cancel the lookup rule if the field value is not 'run'
        LFForm.onLookupTrigger(function() {
            return { cancelLookup: true }; // Cancel the lookup rule
        }, { lookupRuleId: 2 });
    }
}, { fieldId: 39 });

 

Thanks for your time on it.

 

0 0

Replies

replied two days ago

I do not believe there is a way in Javascript to trigger the lookup directly.  If a field is used to trigger the lookup, you could trigger a change to that field via Javascript, which would then trigger the lookup.  But as you said, there is no "where" condition on your lookup, so there's nothing to trigger.

Without a "where" condition, your lookup really only runs on the form being loaded.

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

Sign in to reply to this post.