Saturday, January 31, 2009

How to add lookup field in an entity

There are times when we need to select a value from a set of values.

Now the set of values may be fixed or might not be fixed (that is coming from another table or in other words some dynamic set of values are there)

Now for these two options we have two solutions: Picklist or Lookup

Picklists are mostly used when we have a fixed or defined set of values but for dynamic values or picking values from a table, we can use custom entity and add it as a lookup to our form.

Now to achieve this we just need to create a 1:N relationship in the Table entity to the entity which we want the lookup to be. By Table entity,I mean the table that which we need to display in lookup.

1. Go to : Settings->Customization->Customize entities.

2. Create a new entity for the new table data.

3. Every entity has a primary field. This field gets shown up in the lookup. Name this field appropriately.

4. Publish this entity.

5. Now double click any other entity, where we would want the lookup.

6. In the left navigation pane, we'll find N:1 relationships.Create an N:1 relationship with the entity created in step 2.

7. Now go to forms and views on the same entity. Click on Main Form.

8. Select 'Add fields'.

9. Add the required lookup field.

10. Publish the changes.

11. Populate the entity created in step 2 with data and say cheers as its done.