Post

2 followers Follow
0
Avatar

C# - How to create a timesheet instance?

Hi, I recently learned how to use the Clarizen Web Services for my C# Desktop Application. I have been able to query, but have no success creating new instance of the application. 

I'm trying to create a new TimeSheet entity using this CreateMessage:

new CreateMessage()
      {
        Entity =
          new GenericEntity()
          {
            Id = new EntityId() { TypeName = "TimeSheet"},
            Values = new FieldValue[]{
               new FieldValue() { FieldName = "Comment"     , Value = p.Comment },
               new FieldValue() { FieldName = "Duration"    , Value = new Duration() { Unit = DurationUnit.Hours, Value = (double)p.Duration / 60 } },
               new FieldValue() { FieldName = "WorkItem"    , Value = new BaseEntity(){ Id = new EntityId(){ TypeName="WorkItem", Value = p.WorkItem } } },
               new FieldValue() { FieldName = "ReportedBy"  , Value = new BaseEntity(){ Id = new EntityId(){ TypeName="User", Value = p.ReportedBy } } },
               new FieldValue() { FieldName = "State"       , Value = "Approved" },
               new FieldValue() { FieldName = "ReportedDate", Value = p.ReportedDate },
            }
          }
      };

However, I keep getting the System.Web.Services.Protocol.SoapException with a message "Cannot create an abstract class."

Any help would be greatly appreciated.

Thanks

Vinh Tran Answered

Please sign in to leave a comment.

3 comments

0
Avatar

Hi Vinh.

The WorkItemReportedBy are Reference fields as you noticed. Field values provided for Create/Update messages should be of type EntityId _directly (you don't need to wrap it in a _BaseEntity). Check out my last comment in this post (https://success.clarizen.com/entries/45197893-Creating-Discussion-from-API-v6-), particularly the value for Container field.

BTW, BaseEntity is an abstract class, so you never need to use it directly. 

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink