Creating Assets
This topic explains how to create new assets in .NET SDK.
Overview
When you create a new asset with the .NET SDK,you need to specify the context of another asset that will be the parent. For example, if you create a new Story asset you can specify which Scope (project) it should be created in.
Prior to creating an asset in Digital.ai Agility , you must first instantiate a V1Connector and Services object:
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.Build();
IServices services = new Services(connector);
In versions of the SDK prior to the 15.0.0.0 release, you would also have to instantiate a connector for the MetaModelobject. However, starting with the 15.0.0.0 release, that is no longer necessary. TheMetaModelobject is now available from theMetaproperty of theServicesobject.
Creating a New Asset
This example shows how tocreate a Story asset in the context of a Scope with ID 1012:
Oid projectId = services.GetOid("Scope:1012");
IAssetType storyType = services.Meta.GetAssetType("Story");
Asset newStory = services.New(storyType, projectId);
IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name");
newStory.SetAttributeValue(nameAttribute, "My New Story");
services.Save(newStory);
Console.WriteLine(newStory.Oid.Token);
Console.WriteLine(newStory.GetAttribute(storyType.GetAttributeDefinition("Scope")).Value);
Console.WriteLine(newStory.GetAttribute(nameAttribute).Value);
/***** OUTPUT *****
Story:1094
Scope:1012
My New Story
******************/