<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx</link><description>Sorry I haven&amp;rsquo;t been blogging in a while. I&amp;rsquo;ve been on a whirlwind tour around South Africa and Europe for the last three weeks presenting about Service Manager in one forum or another essentially every day. It&amp;rsquo;s been exciting, but hasn&amp;rsquo;t</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3476807</link><pubDate>Mon, 23 Jan 2012 17:49:26 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3476807</guid><dc:creator>Travis Wright MSFT</dc:creator><description>&lt;p&gt;@Scott - the most common case for that error message happens when you are applying a template which has an action log entry defined in it. &amp;nbsp;That doesnt work because each action log entry has a unique ID. &amp;nbsp; If that ID is used once for a particular incident then it will fail the next time you try to add an action log entry to a different incident with the same action log entry ID.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3476807" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3476794</link><pubDate>Mon, 23 Jan 2012 17:03:08 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3476794</guid><dc:creator>Scott</dc:creator><description>&lt;p&gt;Travis, how do you use this to apply an Incident template to an existing Incident object or type projection, I always get an error&lt;/p&gt;
&lt;p&gt;Microsoft.EnterpriseManagement.Common.DiscoveryDataLifetimeDependencyException: A discovery data item was rejected because the item is already bound to another Membership relationship.&lt;/p&gt;
&lt;p&gt;I am adding a &amp;#39;WorkItemAssignedToUser&amp;#39; to the incident type projection and commiting it&lt;/p&gt;
&lt;p&gt;I then try to apply the template (which has some fields changed on it such as the urgency etc) and get this error&lt;/p&gt;
&lt;p&gt;Any ideas&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3476794" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3472734</link><pubDate>Fri, 23 Dec 2011 15:07:34 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3472734</guid><dc:creator>Apply teamplate via projection</dc:creator><description>&lt;p&gt;Seems to me I&amp;#39;m somewhere near&lt;/p&gt;
&lt;p&gt;===script 3===&lt;/p&gt;
&lt;p&gt;clear&lt;/p&gt;
&lt;p&gt;$sr_class = get-scsmclass -name System.WorkItem.ServiceRequest$&lt;/p&gt;
&lt;p&gt;$sr_prior = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Medium&lt;/p&gt;
&lt;p&gt;$sr_urg = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Medium&lt;/p&gt;
&lt;p&gt;$title = &amp;quot;TEST SR Title 123&amp;quot;&lt;/p&gt;
&lt;p&gt;$area = get-SCSMEnumeration -Name ServiceRequestAreaEnum.FinamInternetAccess&lt;/p&gt;
&lt;p&gt;New-SCSMOBject -Class $sr_class -PropertyHashtable `&lt;/p&gt;
&lt;p&gt;(@{`&lt;/p&gt;
&lt;p&gt;Title = $title; `&lt;/p&gt;
&lt;p&gt;Urgency = $sr_urg; `&lt;/p&gt;
&lt;p&gt;Priority = $sr_prior; `&lt;/p&gt;
&lt;p&gt;ID = &amp;quot;SR#{0}&amp;quot;; `&lt;/p&gt;
&lt;p&gt;Area = $area `&lt;/p&gt;
&lt;p&gt;})&lt;/p&gt;
&lt;p&gt;$sr = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequestProjection$ | ? { &amp;quot;Id -eq &amp;#39;$title&amp;#39;&amp;quot; }&lt;/p&gt;
&lt;p&gt;$template = Get-SCSMObjectTemplate -DisplayName &amp;quot;&amp;lt;blah-blah&amp;gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;Set-SCSMObjectTemplate -Projection $sr -Template $template&lt;/p&gt;
&lt;p&gt;===script 3===&lt;/p&gt;
&lt;p&gt;===out 3===&lt;/p&gt;
&lt;p&gt;Set-SCSMObjectTemplate : Cannot convert &amp;#39;System.WorkItem.ServiceRequestProjection&amp;#39; to the type &amp;#39;Microsoft.EnterpriseManagement.&lt;/p&gt;
&lt;p&gt;Common.EnterpriseManagementObjectProjection[]&amp;#39; required by parameter &amp;#39;Projection&amp;#39;. Object cannot be stored in an array of this &lt;/p&gt;
&lt;p&gt;type.&lt;/p&gt;
&lt;p&gt;At D:\work\new-sr.ps1:18 char:35&lt;/p&gt;
&lt;p&gt;+ Set-SCSMObjectTemplate -Projection &amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;nbsp;$sr -Template [Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectProje&lt;/p&gt;
&lt;p&gt;ction]$template&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidArgument: (:) [Set-SCSMObjectTemplate], ParameterBindingException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : CannotConvertArgument,SMLets.SetSCSMObjectTemplateCommand&lt;/p&gt;
&lt;p&gt;===out 3===&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3472734" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3472694</link><pubDate>Fri, 23 Dec 2011 09:57:59 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3472694</guid><dc:creator>New-SCSMObject with Service Request Template</dc:creator><description>&lt;p&gt;Travis,&lt;/p&gt;
&lt;p&gt;How to perform this with powershell with Service Requests?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to put different Ids for &amp;nbsp;TemplateId in New-SCSMObject. Still didn&amp;#39;t succeeded.&lt;/p&gt;
&lt;p&gt;=====script 1=====&lt;/p&gt;
&lt;p&gt;$sr_class = get-scsmclass -name System.WorkItem.ServiceRequest$&lt;/p&gt;
&lt;p&gt;$sr_prior = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Medium&lt;/p&gt;
&lt;p&gt;$sr_urg = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Medium&lt;/p&gt;
&lt;p&gt;$title = &amp;quot;TEST SR Title&amp;quot;&lt;/p&gt;
&lt;p&gt;$templ_id = Get-SCSMObjecttemplate | ? { $_.displayname -match &amp;quot;&amp;lt;blah-blah-blah&amp;gt;&amp;quot; }&lt;/p&gt;
&lt;p&gt;New-SCSMOBject -Class $sr_class -PropertyHashtable `&lt;/p&gt;
&lt;p&gt;(@{`&lt;/p&gt;
&lt;p&gt;Title = $title; `&lt;/p&gt;
&lt;p&gt;Urgency = $sr_urg; `&lt;/p&gt;
&lt;p&gt;Priority = $sr_prior `&lt;/p&gt;
&lt;p&gt;}) -Template $templ_id&lt;/p&gt;
&lt;p&gt;=====script 1=====&lt;/p&gt;
&lt;p&gt;gives an error&lt;/p&gt;
&lt;p&gt;=====out 1=====&lt;/p&gt;
&lt;p&gt;New-SCSMObject : Only a template targeted at a class can be applied to a single object.&lt;/p&gt;
&lt;p&gt;At D:\work\test2.ps1:21 char:15&lt;/p&gt;
&lt;p&gt;+ New-SCSMOBject &amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;nbsp;-Class $sr_class -PropertyHashtable `&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: NotSpecified: (:) [New-SCSMObject], InvalidOperationException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : System.InvalidOperationException,SMLets.NewSMObjectCommand&lt;/p&gt;
&lt;p&gt;=====out 1=====&lt;/p&gt;
&lt;p&gt;And this one doesn&amp;#39;t apply the template&lt;/p&gt;
&lt;p&gt;=====script 2=====&lt;/p&gt;
&lt;p&gt;$sr_class = get-scsmclass -name System.WorkItem.ServiceRequest$&lt;/p&gt;
&lt;p&gt;$sr_prior = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Medium&lt;/p&gt;
&lt;p&gt;$sr_urg = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Medium&lt;/p&gt;
&lt;p&gt;$title = &amp;quot;TEST SR Title&amp;quot;&lt;/p&gt;
&lt;p&gt;$templ_id = (Get-SCSMObjecttemplate | ? { $_.displayname -match &amp;quot;&amp;lt;blah-blah-blah&amp;gt;&amp;quot; }).id.tostring()&lt;/p&gt;
&lt;p&gt;New-SCSMOBject -Class $sr_class -PropertyHashtable `&lt;/p&gt;
&lt;p&gt;(@{`&lt;/p&gt;
&lt;p&gt;Title = $title; `&lt;/p&gt;
&lt;p&gt;Urgency = $sr_urg; `&lt;/p&gt;
&lt;p&gt;Priority = $sr_prior; `&lt;/p&gt;
&lt;p&gt;TemplateId = $templ_id `&lt;/p&gt;
&lt;p&gt;})&lt;/p&gt;
&lt;p&gt;=====script 2=====&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3472694" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3446843</link><pubDate>Sat, 13 Aug 2011 00:46:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3446843</guid><dc:creator>Shawnbe</dc:creator><description>&lt;p&gt;Hi Travis,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to apply a Change Request template that contains activities. I notice that the activities that get created after applying the template don&amp;#39;t have the correct prefixes. Do I need to iterate through all the related items and make sure they have their prefixes set?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3446843" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3422952</link><pubDate>Wed, 20 Apr 2011 02:44:26 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3422952</guid><dc:creator>Travis Wright MSFT</dc:creator><description>&lt;p&gt;@Rob - No problem. &amp;nbsp;Hang in there. &amp;nbsp;Check out this blog post:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.technet.com/b/servicemanager/archive/2010/10/04/using-the-sdk-to-create-and-edit-objects-and-relationships-using-type-projections.aspx"&gt;blogs.technet.com/.../using-the-sdk-to-create-and-edit-objects-and-relationships-using-type-projections.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Especially example #5.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3422952" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3422950</link><pubDate>Wed, 20 Apr 2011 02:40:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3422950</guid><dc:creator>Rob</dc:creator><description>&lt;p&gt;@Travis - thanks for bearing with me. I think the problem here is my luck of understanding in this particular area. I don&amp;#39;t know how to create a new incident (or other class) using an emop instead of a cemo, if you have a blog example perhaps you could point me at it?&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve gotten around it for now by hard-coding the required values into the code.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3422950" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3422948</link><pubDate>Wed, 20 Apr 2011 02:27:39 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3422948</guid><dc:creator>Travis Wright MSFT</dc:creator><description>&lt;p&gt;If you have a cemo and you want to apply a template to it you need to have a template which has a class as the TypeID instead of TypeProjection for the TypeID.&lt;/p&gt;
&lt;p&gt;Rather than use a cemo can you use an emop as above?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3422948" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3422944</link><pubDate>Wed, 20 Apr 2011 02:00:54 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3422944</guid><dc:creator>Rob</dc:creator><description>&lt;p&gt;@Travis - thanks - I don&amp;#39;t really understand how to apply that (to my cemo), I&amp;#39;ll do some more research...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3422944" width="1" height="1"&gt;</description></item><item><title>re: Creating (or Editing) an Object From a Template Programmatically</title><link>http://blogs.technet.com/b/servicemanager/archive/2010/11/07/creating-an-object-from-a-template-programmatically.aspx#3422943</link><pubDate>Wed, 20 Apr 2011 01:54:09 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3422943</guid><dc:creator>Travis Wright MSFT</dc:creator><description>&lt;p&gt;@Rob - Sorry I forgot for some reason we dont have a CreatableEnterpriseManagementObjectProjection class. &amp;nbsp;You just need to do it like the example above:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//This is how you apply a template to a new object projection you want to create:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EnterpriseManagementObjectProjection emop = new EnterpriseManagementObjectProjection(emg, mpt);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;emop.Overwrite();&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3422943" width="1" height="1"&gt;</description></item></channel></rss>