Prevent Record Creation when Certain Conditions are Met

Posted by Rollbase User on 06-Oct-2011 04:38

Can anybody suggest a way to prevent creation of new Record in an Object based on certain conditions? For example, a Parent Object "Section" has a field labeled "Max Students" with the value 20. It has a Child Object named "Students". The Section Object must contain a number of records equal or less than the value of "Max Students". When the number of students before record creation reaches the maximum value, it should do either: - hide the New Student link in the view; or - shows a message that the user cannot create a new record because the maximum records has been reached. Is this possible with Rollbase / JavaScript?

All Replies

Posted by Admin on 06-Oct-2011 11:38

This can be done through validation triggers. These triggers can be created to insure various types of data integrity.



In your case before creating a new student run validation trigger which would count number of students in parent section (by running Query API) and rise an error if that number is too high.

Posted by Admin on 21-Oct-2011 03:39

Thanks Pavel.



However, what we need is to prevent the user from creating a new record; Rollbase should display an error message before the user gets the chance to enter any information and should be redirected to the List page.



Posted by Admin on 25-Oct-2011 21:00

You can alternatively Hide the New Student Link in it's related list view on the Section's View Page via JavaScript, you can use these Calls in the view page:



document.getElementById("rbi_S_"+rbf_getSectionIdByTitle("place section title of list view") ).getElementsByTagName('a').item(0).style.display = 'none';



-- or --



document.getElementById("rbi_S_"+rbf_getSectionIdByTitle("place section title of list view") ).getElementsByTagName('a').item(0).style.visibility = 'hidden';



You can then add your conditions before calling the said function, e.g. :

if (parseInt('{!students}') > parseInt('{!max_students}')) {

// call your codes here

}



You can append these codes either to the onLoad function or the onTab function of your section's view page.



Thank you and hope this helps,

Piscoso Martin

Posted by Admin on 27-Oct-2011 02:30

Thanks Martin!



This is exactly what we were looking for. Will feedback once we tried this.

This thread is closed