Add Rule on Lookup field

Home Forums General discussion Add Rule on Lookup field

Viewing 1 reply thread
  • Author
    Posts
    • #38414
      Rabih Naouss
      Participant

        Hello

        I have a lookup field (within the same site) with multiple selection.
        How can I set a rule on this field ?
        For example: the field is residence country, if the user select a specific country we need to set list of fields as mandatory.
        Please advise

        Thanks
        Regards

      • #38421
        Alexander Bautz
        Keymaster

          Hi,
          I assume that this is the classic DFFS.

          You must create a rule that has the trigger “No trigger (must be triggered manually)” and then use Custom JS like this:

          // No changes to this function
          function detectChangesOnMultiLookup(arg){
              let currSelection = getFieldValue(arg.fin);
              setInterval(function(){
                  let newVal = getFieldValue(arg.fin);
                  if(newVal.toString() !== currSelection.toString()){
                      currSelection = newVal;
                      currSelection.forEach(function(v){
                          if(v === arg.targetValue){
                              arg.callback();
                          }
                      });
                  }
              },1000);
          }
          
          // Change fin, targetValue and TriggerMeOnLookupColumnChange
          detectChangesOnMultiLookup({fin: "MultiLookup", targetValue: "Test item #3", callback: function(){
               spjs.dffs.triggerRule("TriggerMeOnLookupColumnChange")
          }});
          

          Change the fin (MultiLookup) with the internal name of your lookup field and the targetValue (Test item #3) with the target value. Change TriggerMeOnLookupColumnChange to match the rule friendly name of the rule you want to trigger.

          Alexander

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.