none
Quick launch a Template Form

    Question

  • Hi!

    Trying to create a custom console task to quick launch the Default Service Request form template.

    namespace WpfControlLibrary3
    {
    	class CallServiceRequestTemplate : ConsoleCommand
    	{
    		public override void ExecuteCommand(IList<NavigationModelNodeBase> nodes, NavigationModelNodeTask task, ICollection<string> parameters)
    		{
    			IManagementGroupSession session = (IManagementGroupSession)FrameworkServices.GetService<IManagementGroupSession>();
    			EnterpriseManagementGroup emg = session.ManagementGroup;
    			ManagementPackObjectTemplate mpt = emg.Templates.GetObjectTemplate(new Guid("03bc9162-041f-c987-8ce4-a5547cd9ca04"));
    
    			// Something Here ???????
    		}
    	}
    }
    I am a newbie in SDK. I can't find any examples of code about this. Only this. But not sure that it what is i need. Any help or examples very appreciated.


    Если сообщение оказалось полезным, пожалуйста, проголосуйте за него или пометьте в качестве ответа.


    • Edited by Dismantled Thursday, December 05, 2013 7:58 PM
    Thursday, December 05, 2013 7:57 PM

Answers

  • Opening a form is not done with the supported SDK. It's done with the unsupported Console API.

    You already have your template, that's good. You'll also need the seed (or root) class of that template. In other words, you'll need the Service Request management pack class.

    ManagementPackClass mpc = emg.EntityTypes.GetClass(new Guid("04B69835-6343-4DE2-4B19-6BE08C612989")); //System.WorkItem.ServiceRequest

    NavigationModelNodeBase nodeIn = nodes[0]; NavigationModelNodeBase nmnbNew; NavigationModelNodeTask nmntNew = NavigationTasksHelper.CreateNewInstanceLink(mpc, mpt); GenericCommon.MonitorCreatedForm(nodeIn, nmntNew, out nmnbNew);

    So, basically, insert this code where you have "Something Here ??????".

    There's nothing fancy here. In other words, "MonitorCreatedForm" fires asynchronously..so your task code will end right away..but the form will open on it's own thread.

    The reason you won't find this code documented is because the Console API is not supported by Microsoft and may change in future versions of Service Manager (potentially rendering your task obsolete..or worse..it'll start crashing).

    Incidentally, while it's pretty much necessary in this instance, I recommend you not mix the SCSM SDK and the Console API together..it's usually safer that way :) But, like I said, in this case it's sort of necessary since the CreateNewInstanceLink method actually requires SCSM SDK objects.


    edit: by the way, i obviously didn't include any error handling/trapping in my code..you'll probably want to in your code :)
    • Edited by Aaron Croasmun Thursday, December 05, 2013 11:04 PM
    • Marked as answer by Dismantled Friday, December 06, 2013 3:02 PM
    Thursday, December 05, 2013 11:01 PM
  • In your MP, this line: <Argument Name="Type">WpfControlLibrary3.WpfControlLibrary3TaskHandler</Argument> should be: <Argument Name="Type">WpfControlLibrary3.CallServiceRequestTemplate</Argument> CallServiceRequestTemplate is the name of the class (the type) you're trying to instantiate as a console task. I'm not sure where WpfControlLibrary3TaskHandler came from??
    • Marked as answer by Dismantled Friday, December 06, 2013 3:02 PM
    Friday, December 06, 2013 2:47 PM

All replies

  • Opening a form is not done with the supported SDK. It's done with the unsupported Console API.

    You already have your template, that's good. You'll also need the seed (or root) class of that template. In other words, you'll need the Service Request management pack class.

    ManagementPackClass mpc = emg.EntityTypes.GetClass(new Guid("04B69835-6343-4DE2-4B19-6BE08C612989")); //System.WorkItem.ServiceRequest

    NavigationModelNodeBase nodeIn = nodes[0]; NavigationModelNodeBase nmnbNew; NavigationModelNodeTask nmntNew = NavigationTasksHelper.CreateNewInstanceLink(mpc, mpt); GenericCommon.MonitorCreatedForm(nodeIn, nmntNew, out nmnbNew);

    So, basically, insert this code where you have "Something Here ??????".

    There's nothing fancy here. In other words, "MonitorCreatedForm" fires asynchronously..so your task code will end right away..but the form will open on it's own thread.

    The reason you won't find this code documented is because the Console API is not supported by Microsoft and may change in future versions of Service Manager (potentially rendering your task obsolete..or worse..it'll start crashing).

    Incidentally, while it's pretty much necessary in this instance, I recommend you not mix the SCSM SDK and the Console API together..it's usually safer that way :) But, like I said, in this case it's sort of necessary since the CreateNewInstanceLink method actually requires SCSM SDK objects.


    edit: by the way, i obviously didn't include any error handling/trapping in my code..you'll probably want to in your code :)
    • Edited by Aaron Croasmun Thursday, December 05, 2013 11:04 PM
    • Marked as answer by Dismantled Friday, December 06, 2013 3:02 PM
    Thursday, December 05, 2013 11:01 PM
  • Aaron thank you so much for detailed answer.

    But something wrong with my code.

    Here is C#:

    namespace WpfControlLibrary3
    {
    	class CallServiceRequestTemplate : ConsoleCommand
    	{
    		public override void ExecuteCommand(IList<NavigationModelNodeBase> nodes, NavigationModelNodeTask task, ICollection<string> parameters)
    		{
    			IManagementGroupSession session = (IManagementGroupSession)FrameworkServices.GetService<IManagementGroupSession>();
    			EnterpriseManagementGroup emg = session.ManagementGroup;
    			ManagementPackObjectTemplate mpt = emg.Templates.GetObjectTemplate(new Guid("03bc9162-041f-c987-8ce4-a5547cd9ca04"));
    			ManagementPackClass mpc = emg.EntityTypes.GetClass(new Guid("04b69835-6343-4de2-4b19-6be08c612989"));
    			//System.WorkItem.ServiceRequestNavigationModelNodeBase nodeIn = nodes[0];
    			NavigationModelNodeBase nmnbNew;
    			NavigationModelNodeTask nmntNew = NavigationTasksHelper.CreateNewInstanceLink(mpc, mpt);
    			GenericCommon.MonitorCreatedForm(nodes[0], nmntNew, out nmnbNew);
    			//GenericCommon.MonitorCreatedForm(nodeIn, nmntNew, out nmnbNew);
    		}
    	}
    }

    Here is MP:

    <ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <Manifest>
    <Identity>
    <ID>ManagementPack.5dd78e73bb854f00b0938145cea65602</ID>
    <Version>7.5.2905.0</Version>
    </Identity>
    <Name>ДЕПО - Консольный таск вызова шаблона Запроса на обслуживание</Name>
    <References>
    <Reference Alias="EnterpriseManagement">
    <ID>Microsoft.EnterpriseManagement.ServiceManager.UI.Console</ID>
    <Version>7.5.2905.0</Version>
    <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    </Reference>
    <Reference Alias="CustomSystem_Library">
    <ID>System.Library</ID>
    <Version>7.5.8501.0</Version>
    <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    </Reference>
    </References>
    </Manifest>
    <Categories>
    <Category ID="Category.MultiSelectTask.DeleteCostCenter" Target="ConsoleTask.WpfControlLibrary3" Value="EnterpriseManagement!Microsoft.EnterpriseManagement.ServiceManager.UI.Console.MultiSelectTask" />
    <Category ID="Category.b3043f92bd9a495791ee6847475d4b6b" Value="EnterpriseManagement!Microsoft.EnterpriseManagement.ServiceManager.ManagementPack">
    <ManagementPackName>ManagementPack.5dd78e73bb854f00b0938145cea65602</ManagementPackName>
    <ManagementPackVersion>7.5.2905.0</ManagementPackVersion>
    </Category>
    </Categories>
    <Presentation>
    <ConsoleTasks>
    <ConsoleTask ID="ConsoleTask.WpfControlLibrary3" Accessibility="Public" Enabled="true" Target="CustomSystem_Library!System.Entity" RequireOutput="false">
    <Assembly>EnterpriseManagement!SdkDataAccessAssembly</Assembly>
    <Handler>Microsoft.EnterpriseManagement.UI.SdkDataAccess.ConsoleTaskHandler</Handler>
    <Parameters>
    <Argument Name="Assembly">WpfControlLibrary3</Argument>
    <Argument Name="Type">WpfControlLibrary3.WpfControlLibrary3TaskHandler</Argument>
    </Parameters>
    </ConsoleTask>
    </ConsoleTasks>
    <ImageReferences>
    <ImageReference ElementID="ConsoleTask.WpfControlLibrary3" ImageID="EnterpriseManagement!Microsoft.EnterpriseManagement.ServiceManager.UI.Console.Image.Remove" />
    </ImageReferences>
    </Presentation>
    <LanguagePacks>
    <LanguagePack ID="RUS" IsDefault="true">
    <DisplayStrings>
    <DisplayString ElementID="ManagementPack.5dd78e73bb854f00b0938145cea65602">
    <Name>ДЕПО - Консольный таск вызова шаблона Запроса на обслуживание</Name>
    <Description />
    </DisplayString>
    <DisplayString ElementID="ConsoleTask.WpfControlLibrary3">
    <Name>Создать запрос</Name>
    </DisplayString>
    </DisplayStrings>
    </LanguagePack>
    <LanguagePack ID="ENU" IsDefault="false">
    <DisplayStrings>
    <DisplayString ElementID="ManagementPack.5dd78e73bb854f00b0938145cea65602">
    <Name>ДЕПО - Консольный таск вызова шаблона Запроса на обслуживание</Name>
    <Description />
    </DisplayString>
    <DisplayString ElementID="ConsoleTask.WpfControlLibrary3">
    <Name>Open SR Template</Name>
    </DisplayString>
    </DisplayStrings>
    </LanguagePack>
    </LanguagePacks>
    <Resources>
    <Assembly ID="Assembly.WpfControlLibrary3" Accessibility="Public" FileName="WpfControlLibrary3.dll" HasNullStream="false" QualifiedName="WpfControlLibrary3, Version=1.0.0.0" />
    </Resources>
    </ManagementPack>

    Importing of bundeled MP is OK. And the Task is displayed in Conosle. But on execution it displays error:

    Date: 06/12/13 17:54:50
    Application: System Center Service Manager
    Application Version: 7.5.2905.0
    Severity: Error
    Message: Object reference not set to an instance of an object.

    System.NullReferenceException: Object reference not set to an instance of an object.
    at Microsoft.EnterpriseManagement.UI.SdkDataAccess.ConsoleTaskHandler.DoTask(IList`1 navigationNodes, NavigationModelNodeTask task, List`1 parameterList)
    at Microsoft.EnterpriseManagement.UI.SdkDataAccess.ConsoleTaskHandler.DoTask(IList`1 navigationNodes, NavigationModelNodeTask task)
    at Microsoft.EnterpriseManagement.ConsoleFramework.WindowJobRecord.ExecuteBackgroundJob(Object sender, ConsoleJobEventArgs eventargs)
    at Microsoft.EnterpriseManagement.ServiceManager.UI.Console.ConsoleJobExceptionHandler.ExecuteJob(IComponent component, EventHandler`1 job, Object sender, ConsoleJobEventArgs args)

    I think problem is in the link of my task with request object.

    http://sdrv.ms/1gcnaNr (sorry, forum pic uploading is broken now :( )

    My target is to create a separate console task. Like this:

    http://sdrv.ms/1cq6VsS

    Если сообщение оказалось полезным, пожалуйста, проголосуйте за него или пометьте в качестве ответа.

    Friday, December 06, 2013 2:18 PM
  • In your MP, this line: <Argument Name="Type">WpfControlLibrary3.WpfControlLibrary3TaskHandler</Argument> should be: <Argument Name="Type">WpfControlLibrary3.CallServiceRequestTemplate</Argument> CallServiceRequestTemplate is the name of the class (the type) you're trying to instantiate as a console task. I'm not sure where WpfControlLibrary3TaskHandler came from??
    • Marked as answer by Dismantled Friday, December 06, 2013 3:02 PM
    Friday, December 06, 2013 2:47 PM
  • OOOhh! :-D

    It is from my previous MP-template. Now it works! Thank you so much!


    Если сообщение оказалось полезным, пожалуйста, проголосуйте за него или пометьте в качестве ответа.

    Friday, December 06, 2013 3:01 PM
  • I'm trying to achieve basically the same thing as you, however I cannot compile due to this line: GenericCommon.MonitorCreatedForm(nodeIn, nmntNew, out nmnbNew);

    What reference is required to use this? 
    I'm getting the error: "The name 'GenericCommon' does not exist in the current context".

    Thanks,

    Pietro


    Tuesday, December 10, 2013 1:38 PM
  • Microsoft.EnterpriseManagement.ServiceManager.Application.Common.dll
    Microsoft.EnterpriseManagement.GenericForm.GenericCommon.MonitorCreatedForm()

     

     


    Rob Ford scsmnz.net
    Cireson www.cireson.com
    For a free SCSM 2012 Notify Analyst app click here

    Wednesday, December 11, 2013 2:12 AM
  • Got it working. Thanks!

    Pietro

    Wednesday, December 11, 2013 8:45 PM