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

Create a new company

Audience:
api
•
Version: 10
Some tooltip text!
• 3 minutes to read
 • 3 minutes to read

These examples show how to create a new default contact, assign values to the properties of the entity and save it using the different integration points in SuperOffice.

  • Restful REST
  • RPC Agent
  • Services
company = Get("api/v1/Contact/default")
company.Name = "New company"
company.Category.Id = 2
company = Post("api/v1/Contact", company)
company = Post("api/v1/Agents/Contact/CreateDefaultContactEntity")
company.Name = "New company"
company.Category.Id = 2
company.Business.Id = 3
company.NoMailing = true
company = Post("api/v1/Agents/Contact/SaveContactEntity", company)
Note

The examples are given in JavaScripty pseudocode.

using SuperOffice.CRM.Services;
using SuperOffice;

using(SoSession newSession = SoSession.Authenticate("SAL0", ""))
{
  //Retrieve a ContactAgent
  using(ContactAgent contactAgent = new ContactAgent())
  {
    //Create a new contact Entity with default values set to its properties
    ContactEntity myContact = contactAgent.CreateDefaultContactEntity();

    //Assign values to various properties of the contact entity

    //Assign values to properties of basic data types
    myContact.Name = "Paba Inc.";
    myContact.Department = "Head office";
    myContact.NoMailing = true;

    //Create an array of EntityElement and assign it to the Phones property
    EntityElement[] myPhones = new EntityElement[2];
    myPhones[0] = new EntityElement();
    myPhones[1] = new EntityElement();
    myPhones[0].Value = "0112732006";
    myPhones[1].Value = "0713243288";
    myContact.Phones = myPhones;

    // Set the new contact’s  our-contact to associate 2
    using(AssociateAgent associateAgent = new AssociateAgent())
    {
      Associate myAssociate = associateAgent.GetAssociate(2);
      myContact.Associate = myAssociate;

      // Set the contact’s address
      myContact.Address[0][0].Value = "98/1,Main Street, Inland";
      myContact.Address[3][0].Value = "10620,";
      myContact.Address[3][1].Value = "Inland";  

      //Save the Contact Entity and the new person through the ContactAgent
      // the returned entity has the contact ID filled in
      myContact = contactAgent.SaveContactEntity(myContact);
    }
  }
}

Here we have used a ContactAgent and the CreateDefaultContactEntity method to create a new contact entity with default values filled in. We first set some of the basic values like name and department.

Then we have set values to properties of complex data types such as EntityElement[] types, entity types such as Associate, entity collection types such as Persons, and LocalizedField types.

Finally, the newly created contact entity is saved to the database using the SaveContactEntity method of the agent. With this, a new record will be added to the contact table in the database with its fields set to values that have been assigned.

The entity is returned with the allocated ID filled in.

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