Hello,
I have a loop and I would like to exit the loop once I have found a value with a particular status in the loop. How can we do this using the LOOP_BEGIN and LOOP_END scenario?
var hasOpen = false; {!#LOOP_BEGIN.R5707634#whjW7ZHgRyy6c7ADnW5sMA} if({!R5707634.isOpen#value}){ hasOpen = true;
break; // doesn't work!! } {!#LOOP_END.R5707634} return hasOpen;
Cheers.
Iram
HI Iram,
Currently, this is not supported. Please raise an enhancement request.
You can use Server API - rbv_api.selectQuery() to get the records and use JavaScript for loop to iterate the records with the break statement.
Thanks
Srinivas
Another possible solution is to define the looping construct within a JS function. In the JS function, add a return statement on the break condition.
Eg:
function startLoop(){
{!#LOOP_BEGIN.R5707634#whjW7ZHgRyy6c7ADnW5sMA}
if({!R5707634.isOpen#value}){
return true; // condition to break
}
{!#LOOP_END.R5707634}
return false;
}
//invoke function
startLoop();
Note: Loop template tokens in RB are pre-processed and a copy of embedded statements within a loop is added for each loop record with record specific values. This is done before the JS engine (browser or server-side) interprets the JS code snippet. Hence, it is not considered as an optimal approach for a large number of records esp. for employing static checks. This is more suited for creating HTML markup for each loop record and other similar use-cases. As suggested by Srinivas above, leveraging API support will be more relevant for this requirement.