Create a Row as a property of another entity
Some tooltip text!
• 2 minutes to read
• 2 minutes to read
An Entity can have properties that are of the type Row. A Row object contains properties of basic data types.
These examples show how to create a Row object and assign it to a property of an Entity.
Example 1
Create and modify the properties of a ReasonRow
object through the Sale
Entity.
using SuperOffice;
using SuperOffice.CRM.Entities;
using SuperOffice.CRM.Rows;
using(SoSession newSession = SoSession.Authenticate("jr", "jr"))
{
//Creating a new Sale Entity
Sale newSale = Sale.CreateNew();
newSale.SetDefaults();
//creating a row through the Sale Entity and assigning values
newSale.Reason = ReasonRow.CreateNew();
newSale.Reason.Name = "Resource Utilization";
newSale.Reason.Rank = 10;
//Saving the Sale Entity
newSale.Save();
}
- Create a new
Reason
through the newly createdSale
Entity. - Assign the row to the
Reason
property of the Entity instance. - Call the
Save
method to save theSale
Entity instance and at the same time add a new row to theReason
Table.
Note
You do not need to explicitly create a new Row when using an Entity property. The Entity will create a new blank Row for you automatically.
Example 2
Create CurrencyRow
object and then assign it to the Currency
property of the Sale
Entity.
using SuperOffice;
using SuperOffice.CRM.Entities;
using SuperOffice.CRM.Rows;
using(SoSession newSession = SoSession.Authenticate("SAL0", ""))
{
//Creating a new Sale Entity
Sale newSale = Sale.CreateNew();
newSale.SetDefaults();
//Creating a new Currency Row and assigning it values
CurrencyRow newCurrency = CurrencyRow.CreateNew();
newCurrency.SetDefaults();
newCurrency.Name = "Riyal";
newCurrency.Rank = 5;
newCurrency.Units = 52.25;
newSale.Currency = newCurrency;
//Saving the Sale Entity
newSale.Save();
}
When calling Save()
, the Sale
Entity instance will be saved along with a new row being added to the Currency
table with its name (Riyal), rank (5), and units (52.25) fields with given values. The rest of the columns will have default values.