Populating new Cell with a Contact(s)

I have been reading the SDK for Smartsheet and can't find support for how to populate a cell in a Contact List type column programmatically given the name of a person in the contact list (language C#).

I have line of code that builds the cells, I then add that to a new Row and push to a sheet using AddRows() method. I am able to write to other columns but I can't get the Contact List Column to populate. The data I have is the name of the contact.


string pComment = "Some comment." ;

Contact pContact = "Name"; //I have tried other object and primitive types here but none work.

      Cell[] cellsA = new Cell[] {

        new Cell.AddCellBuilder(6812313465448324,pComment).Build(),//Comments Cell

        new Cell.AddCellBuilder(1745763884656516, pContact).Build(),//Contact Cell

};


//Create Row and add Cells

//Push new Row to Sheet with Sheet ID

//Error

The error comes when adding the Row to the sheet. Does anyone know how to successfully populate the Contact List cell with a contact (assuming the contact exists) by using the name as a string?


I have read other post but none have helped me solved the problem.

-Thanks in advance.

Answers

  • Andria Hoyle
    Andria Hoyle ✭✭✭✭✭

    Following! This is my top priority to learn how to update Contact List automatically.

  • Genevieve P.
    Genevieve P. Employee Admin

    Hi @Christopher Alfaro

    I believe you would need to identify the email of the contact as well as the name. I found this thread in the StackOverflow community that may help: C# SDK Smartsheet Post w/ API

    This is the response:

    With the C# SDK, you can be a little more direct, since you're dealing with a column object that already has a type associated with it. That would look something like this:

     Contact newContact = new Contact();
     newContact.Name = "Susan";
     newContact.Email = "[email protected]";
    
     column.ContactOptions = new Contact[] { newContact };
     ss.SheetResources.ColumnResources.UpdateColumn(sheetId, column);
    

    If your contact column is a Multi contact column, you may want to review the information in this other StackOverflow post, here: Smartsheet - add row with multiple values in cell using c# sdk

    In this example, you'll notice that again the email is referenced for the Contact, not the name.

    Let me know if this has helped!

    Cheers,

    Genevieve

  • @Genevieve P Thanks for your response! Unfortunately it is not quite what I am looking for. To be more clear I need to populate a cell with a predefined Contact (in which the list already exists), your method appends to the list.


    I did find a workaround but it's probably not suitable for large lists, it involves using the formula field and referencing another cell in the sheet that already has the contact filled in.

  • I'm looking for the same answer how to add cell for a column that uses contacts, I've tried several ways and keep getting the same error "The value '[email protected]' could not be saved in column' Originating Engineer'. This column is restricted to CONTACT_LIST values only."

    Any ideas, I can find any examples for the C# SDK or any other SDK?

  • Genevieve P.
    Genevieve P. Employee Admin

    Hi @Stephen J. Naughton

    It sounds like you have the "Restrict to list values only" checkbox checked for that column. Is the contact you're looking to add part of the Column Properties value list? If it's not in this list, you won't be able to add it to the cell.

    Here's the Smartsheet API documentation on the ContactOption Object

    Cheers,

    Genevieve

  • You are correct, I found that although the sheet appeared to list me as a contact when I used the api to get the contact options I was not there so your comment above about how to add a new contact is very useful thanks 👍

  • Hi Genevieve, I've tried you method for adding a new contact when it's missing and I get the following error "The attribute(s) column.version are not allowed for this operation."

    Thanks in advance 👍

  • Genevieve P.
    Genevieve P. Employee Admin

    Hi @Stephen J. Naughton

    The "column.version" in the Column Object identifies what type of column it is:

    A Contact Column should have a Version of 0 if it's Single Select, so if you use a Get Sheet request you'll see something like this for the Contact Column in your sheet, identifying the Version as 0:

    Once you've updated the column list, or the "ContactOptions" to have the email of  '[email protected]' in the column, then you should be able to update rows with the value being this email address and the display value being the name you want associated with the contact.

    If the contact is in the dropdown list with the display name you want already, then you only need to specify the value and it will automatically add the display value for this contact when the row is updated or added.

    Cheers!

    Genevieve