In this post I talked about checking whether a default contact person is an employee of the employer. Instead of using triggers, I started using validations. After researching for a while I was able to come up with the following code:
var found = false; var cpn = 0; if({!R108244245}) { cpn = {!R108244245}; } else { cpn = {!R108244245.id}; } if(cpn) { {!#LOOP_BEGIN.R108244227} if(cpn == {!R108244227.id}) { found = true; } {!#LOOP_END.R108244227} if(!found) {return "Kan niet updaten, er mist een werknemer bij contactpersoon!";} }
It works. However, I do wonder.. Is there a way to do this without having to retry and edit for 2 hours? :/
Thanks in advance!
Hi matman,
What do you mean "without having to retry and edit for 2 hours?".
Thanks,
Gian
I couldn't find a quick way to iterate through the $_POST related records of R108244227. After reading through the Rollbase Documents, I noticed the [tag:LOOP]_BEGIN thing. After playing with it for a while I managed to apply it in my script. But I wasn't able to apply a condition or break statement on or inside the loop. That's why it took so long. Do you know any way to iterate through it without the [tag:LOOP]_BEGIN? :/
Hi matman,
Instead using {!LOOP} to iterate thru all records just to compare a specific ID, can you just use a rbv_api.selectValue function? This will be much faster that looping thru all records of a certain object.
This is not the exact code but will help you rethink your script logic:
var relatedId = parseInt("{!R108244245#id}");
var newId = 0;
if(relatedId > 0){ /*if has a value*/
newId = rbv_api.selectNumber("SELECT id FROM rel_object WHERE id=? AND object_rel_to_this_object=?",relatedId,parseInt("{!id}")); /*gets this objects related records by using {!id} as a filter*/
}
if(newId <= 0){
return "Kan niet updaten, er mist een werknemer bij contactpersoon!";
}
Let me know if this helps.
Thanks,
Gian