Add Rule on Lookup field
- This topic has 1 reply, 2 voices, and was last updated 1 year, 9 months ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- You must be logged in to reply to this topic.
Home › Forums › General discussion › Add Rule on Lookup field
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
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