• Share
    • Twitter
    • LinkedIn
    • Facebook
    • Email
  • Feedback
  • Edit
Show / Hide Table of Contents

SetDefaults method

•
Environment: onsite
Some tooltip text!
• 1 minute to read
 • 1 minute to read

Using the SetDefaults method when inserting data either to Entity or Row types, could be identified as a good practice.

If SetDefault() was not used, the programmer would have to make use of flow-control structures such as if-else blocks to handle situations where the user doesn’t enter any values.

Example

using SuperOffice.CRM.Entities;
using SuperOffice.CRM.Rows;
using(SuperOffice.SoSession mySession = SuperOffice.SoSession.Authenticate("sam", "sam"))
{
  //Creating a Contact Entity
  Contact newContact = Contact.CreateNew();

  //Sets default values - Good Practice
  newContact.SetDefaults();
  newContact.Name = "Jazz";

  //Creating instances of Row types
  EmailRow newEmail1 = EmailRow.CreateNew();
  newEmail1.EmailAddress = "ally@alley.com";
  newEmail1.Description = "Ally's E mail";

  EmailRow newEmail2 = EmailRow.CreateNew();
  newEmail2.EmailAddress = "Anakin@star.com";
  newEmail2.Description = "Anakin's test email";

  PhoneRow newPhone = PhoneRow.CreateNew();
  newPhone.Description = "Jazz's phone number";
  newPhone.Phone = "9771252307";

  //Adding the Row types to the Contact
  newContact.Emails.Add(newEmail1);
  newContact.Emails.Add(newEmail2);
  newContact.Phones.Add(newPhone);

  //Saving the Entity
  newContact.Save();
}

Here, we have created a new Contact Entity and used the SetDefaults method. Because of this, NetServer will fill certain properties of the Entity such as Updated date and Updated Associate.

In This Article
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top