Post

1 follower Follow
0
Avatar

Creating 'Discussion' from API (v6)

Hi,

I'm new to Clarizen. We're using v6. I'm trying to import a few hundred "items" from "the old system".  Each item has zero or more comments associated with it.

I think I want to import these items as "EnhancementRequest" types (subtype of Case), and map the old "comments" to the "Discussion" entity type (a subtype of Comment).

Basing myself on the C# sample from Clarizen, I can create a "Note" (also a subtype of Comment) with the following code.

So this works:

<code>

private void AddNoteToEntity(EntityId caseEntityId)

{

GenericEntity comment = new GenericEntity();

comment.Id = new EntityId();

comment.Id.TypeName = "Note";

FieldValue commentTextValue = new FieldValue();

commentTextValue.FieldName = "Comment";

commentTextValue.Value = "A new comment added " + DateTime.UtcNow.ToLongDateString();

FieldValue attachedToValue = new FieldValue();

attachedToValue.FieldName = "AttachedTo";

attachedToValue.Value = caseEntityId;

comment.Values = new FieldValue[] { commentTextValue, attachedToValue };

CreateMessage createDocument = new CreateMessage();

createDocument.Entity = comment;

Result[] results = clarizen.Execute(new BaseMessage[] { createDocument });

Utils.CheckResponseStatus(results);

}

</code>

But if I change

<code>comment.Id.TypeName = "Note";</code>

to

<code>comment.Id.TypeName = "Discussion";</code>

I receive an error stating that the type "Discussion" does not exist.

 

Alternatively, if I change:

<code>comment.Id.TypeName = "Note";</code>

to

<code>comment.Id.TypeName = "Comment";</code>

I also get an error stating: "Object of a not leaf class 'Collaboration Items' cannot be created"

My guess is the second error is Clarizen's way of telling me it can't create an instance of an abstract type.

But the first error is baffling; how do I create Discussions from the API?

 

Thanks for any assistance!

Stephane Gervais Answered

Please sign in to leave a comment.

2 comments

0
Avatar

Hi Stephane.

First I'd recommend using the new V6 Social features, i.e. use DiscussionPost  which is not BTW a sub-type of Comment.

Knowing the correct API name of entities doesn't have to be guess work, just use ListEntitiesMessageDescribeEntitiesMessage to retrieve the metadata from Clarizen programatically.

Check out this code snippet for creating a post to some project's Discussions

CreateMessage cr = new CreateMessage

{

Entity = new GenericEntity

{

Id = new EntityId { TypeName = "DiscussionPost" },

Values = new FieldValue[]

{

new FieldValue {FieldName = "Body", Value = "Hi"},

new FieldValue {FieldName = "Container", Value = new EntityId {TypeName="Project", Value="17656446-4f00-4d77-a439-0b694d192754"}}

      }

   }

};

 

Hope this helps,

Ophir

 

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Yes, thanks Ophir!

Your code snippet helped me create the DiscussionPost I'd been looking to create.

The suggestion to use ListEntitiesMessage and DescribeEntitiesMessage is proving enlightening to say the least.

Problem solved.

Stephane Gervais 0 votes
Comment actions Permalink