M
matman
Guest
I found the answer to my problem, so now I can also explain why it didn't work for me. Do understand: I'm not the best programmer, my explanation is based on the little experience I have in the programming field. I believe Rollbase uses a virtual database inside a database. This means that when you create an object, a row will be added to the object table, definining that object. When fields are added to that object, rows will be added to the fields table, defining the fields, their values and to which object they link. When a field is actually filled in by the user, the value will be stored in a value table, linking the value to that field (and the field links to the object). Now.. Once you create a relation between two objects (Employer and Employee), a row will be added to the relations table, defining that relation. When you define a 1-1 relation, a field will be added to the field table of ONE of the two objects. Now value Object ID will be linked to that field. When you define a 1-M, M-1, M-M relationship, the Object ID's of these two objects will be stored and linked to that relationship. That's the theory at least. If you actually want to check if an {!id} has a relationship with R............, you must ask yourself first which side of the relationship you are checking. I'll explain this by using my scenario: We have an Employer. This Employer has relationships with his Employees (One Employer to Many Employees). If we want to get all Employees of an Employer, we must ask the Employer for his relationships. If we want to get the Employer of an Employee, we must ask the Employee for his relationship. Now my second scenario: one of the Employees is a default contact person. This means that I had to add a 1-1 relationship (One Employer to One Employee). Now which side are we going to ask? In this case it will be the side of te Employer. You see: the Employer has a default contact person, the Employee does not have a default contact person. So you now only have to make sure that when you create the relationship, you should do so from the correct side. If you create a 1-1 relationship in the Employee object setup, you will create it FROM Employee TO Employer. In my case it is created in the Employer object setup, which means it is created FROM Employer TO Employee. Secondly, we want to check if the Employee has a relationship with the Employer. (See my first post to see why I would want that.) Because the relationship is defined FROM Employer, we need to ask it to the Employer. But first we need to get the Employer. 1. Is Employee of Employer. 2. Is default contact person of Employer. The Employee's trigger runs because it's relationship with the Employee is planned for removal. But it's relationship can only be removed if the Employee is not the Employer's default contact person. I will first need to ask the Employee who his Employer is. Once I know this, I will need to ask the Employer who the default contact person is. And now for the last part of my code: If the default contact person is the Employee, the relationship with the Employee cannot be deleted. Let's translate it to psuedo code: if(Employee has Employer) { if(Employer's Default Contact Person IS NOT Employee) { Employee relationship gets deleted } else { Employee relationship cannot be deleted } } Now let's translate it to Object Script: var employer = rbv_api.getFieldValue("medewerker", {!id}, "R108244227")[0]; if(employer) { if({!id} != rbv_api.getFieldValue("klant", employer, "R108244245")[0]) { return true; } else { return false; } } As you perhaps noticed, I use an index [0] after getFieldValue(). getFieldValue() returns a reference to an array. In this array all the values are stored that were retrieved from that field. Since both times we will only get one index, I will always use index 0. I hoped I could help some people with this!
Continue reading...
Continue reading...