Console Tasks, open Forms and create Relationships

Hi,

I am new to the SDK development and Visual Studio and I am stuck at the following problem:

I have created a console task which can be called from an existing SCSM form - with the idea, that I want to create a related Item(similiar to "create related Change request") - with my newly created class and form.  I am able to create a "in-memory" object and I can also create a relationship to the calling object. I can display the form by using Generic.Common.MonitorCreatedForm and everything seems to be ok (I can set values, the related item (from the calling form) is shown, and i can used the drop down lists etc.) - BUT I am not able to save the newly created "in-Memory" item - whether I press "OK, or Apply" in my form. In Addition to that, there is one strange behaviour of the displayed form: the "size" cannot be changed - and ist opened in the background.

For opening the form I use the following code (which is largely based on Aarons input from here):

 IDataItem NewN = Microsoft.EnterpriseManagement.UI.Extensions.Shared.ConsoleContextHelper.Instance.CreateNewProjectionInstanceBindableItem(guidBSEProj);
 NewN["DisplayName"] = "123345-example";
 IDataItem NewNEmo = NewN["$EMO$"] as IDataItem;
 NavigationModelNodeTask taskk = NavigationTasksHelper.CreateChildInstanceLink (NewNEmo, null);
 SdkNavigationModelNodeBase createlinknode = FormUtilities.Instance.GetCreatedLinkNode(taskk) as SdkNavigationModelNodeBase;
 createlinknode.NodeContext["IDataItemParameter"]= NewN;
 NewN["RelatesToService"] = dataItemBS["$EMO$"];
 GenericCommon.MonitorCreatedForm(nodes, createlinknode);
 

What could be the problem ?

June 20th, 2015 12:38pm

For being new to the SDK (and worse, the console API), you dove straight into the deep-end of the pool! ;) (I tell ya, if Microsoft ever gets rid of that SCSM console, I'll be out of business..)

The code you're trying to use is for creating and relating an in-memory object via a form. Creating and relating an in-memory object via a console task requires using a CreateWithLinkHandler (a completely different approach). There are advantages and limitations to both approaches. Let me go over some of them quick so we make sure you're on the right track.

The limitation to the console task approach is that the parent object must already exist. In other words, you can't use it to link a new in-memory object to another new in-memory object. That probably sounds completely nonsensical, so let me give a quick example of what I'm describing.

Example 1: I'm in the console. I open an existing computer object's form. I then click "Create related MyClass". The MyClass form opens and it's a new in-memory object. That is a legitimate and perfectly acceptable approach.

Example 2: I'm in the console. I click "Create Computer". The computer class form opens and it's empty. I put in a name. Then I click "Create related MyClass". That is _NOT_ allowed because the computer object does not yet exist.

So..before I go any further, do you want to use a console task to create a new in-memory item to relate to an existing item only? If yes, I'll write up some sample code on the CreateWithLinkHandler approach. If not, you'll need to put a button on your form to execute the code you've already written. Let me know :) I'll help you get this one worked out.

Free Windows Admin Tool Kit Click here and download it now
June 20th, 2015 6:44pm

For being new to the SDK (and worse, the console API), you dove straight into the deep-end of the pool! ;) (I tell ya, if Microsoft ever gets rid of that SCSM console, I'll be out of business..)

The code you're trying to use is for creating and relating an in-memory object via a form. Creating and relating an in-memory object via a console task requires using a CreateWithLinkHandler (a completely different approach). There are advantages and limitations to both approaches. Let me go over some of them quick so we make sure you're on the right track.

The limitation to the console task approach is that the parent object must already exist. In other words, you can't use it to link a new in-memory object to another new in-memory object. That probably sounds completely nonsensical, so let me give a quick example of what I'm describing.

Example 1: I'm in the console. I open an existing computer object's form. I then click "Create related MyClass". The MyClass form opens and it's a new in-memory object. That is a legitimate and perfectly acceptable approach.

Example 2: I'm in the console. I click "Create Computer". The computer class form opens and it's empty. I put in a name. Then I click "Create related MyClass". That is _NOT_ allowed because the computer object does not yet exist.

So..before I go any further, do you want to use a console task to create a new in-memory item to relate to an existing item only? If yes, I'll write up some sample code on the CreateWithLinkHandler approach. If not, you'll need to put a button on your form to execute the code you've already written. Let me know :) I'll help you get this one worked out.

  • Marked as answer by Ro Ki 13 hours 48 minutes ago
June 20th, 2015 10:38pm

For being new to the SDK (and worse, the console API), you dove straight into the deep-end of the pool! ;) (I tell ya, if Microsoft ever gets rid of that SCSM console, I'll be out of business..)

The code you're trying to use is for creating and relating an in-memory object via a form. Creating and relating an in-memory object via a console task requires using a CreateWithLinkHandler (a completely different approach). There are advantages and limitations to both approaches. Let me go over some of them quick so we make sure you're on the right track.

The limitation to the console task approach is that the parent object must already exist. In other words, you can't use it to link a new in-memory object to another new in-memory object. That probably sounds completely nonsensical, so let me give a quick example of what I'm describing.

Example 1: I'm in the console. I open an existing computer object's form. I then click "Create related MyClass". The MyClass form opens and it's a new in-memory object. That is a legitimate and perfectly acceptable approach.

Example 2: I'm in the console. I click "Create Computer". The computer class form opens and it's empty. I put in a name. Then I click "Create related MyClass". That is _NOT_ allowed because the computer object does not yet exist.

So..before I go any further, do you want to use a console task to create a new in-memory item to relate to an existing item only? If yes, I'll write up some sample code on the CreateWithLinkHandler approach. If not, you'll need to put a button on your form to execute the code you've already written. Let me know :) I'll help you get this one worked out.

  • Marked as answer by Ro Ki Sunday, June 21, 2015 5:25 PM
Free Windows Admin Tool Kit Click here and download it now
June 20th, 2015 10:38pm

For being new to the SDK (and worse, the console API), you dove straight into the deep-end of the pool! ;) (I tell ya, if Microsoft ever gets rid of that SCSM console, I'll be out of business..)

The code you're trying to use is for creating and relating an in-memory object via a form. Creating and relating an in-memory object via a console task requires using a CreateWithLinkHandler (a completely different approach). There are advantages and limitations to both approaches. Let me go over some of them quick so we make sure you're on the right track.

The limitation to the console task approach is that the parent object must already exist. In other words, you can't use it to link a new in-memory object to another new in-memory object. That probably sounds completely nonsensical, so let me give a quick example of what I'm describing.

Example 1: I'm in the console. I open an existing computer object's form. I then click "Create related MyClass". The MyClass form opens and it's a new in-memory object. That is a legitimate and perfectly acceptable approach.

Example 2: I'm in the console. I click "Create Computer". The computer class form opens and it's empty. I put in a name. Then I click "Create related MyClass". That is _NOT_ allowed because the computer object does not yet exist.

So..before I go any further, do you want to use a console task to create a new in-memory item to relate to an existing item only? If yes, I'll write up some sample code on the CreateWithLinkHandler approach. If not, you'll need to put a button on your form to execute the code you've already written. Let me know :) I'll help you get this one worked out.

  • Marked as answer by Ro Ki Sunday, June 21, 2015 5:25 PM
June 20th, 2015 10:38pm

For being new to the SDK (and worse, the console API), you dove straight into the deep-end of the pool! ;) (I tell ya, if Microsoft ever gets rid of that SCSM console, I'll be out of business..)

The code you're trying to use is for creating and relating an in-memory object via a form. Creating and relating an in-memory object via a console task requires using a CreateWithLinkHandler (a completely different approach). There are advantages and limitations to both approaches. Let me go over some of them quick so we make sure you're on the right track.

The limitation to the console task approach is that the parent object must already exist. In other words, you can't use it to link a new in-memory object to another new in-memory object. That probably sounds completely nonsensical, so let me give a quick example of what I'm describing.

Example 1: I'm in the console. I open an existing computer object's form. I then click "Create related MyClass". The MyClass form opens and it's a new in-memory object. That is a legitimate and perfectly acceptable approach.

Example 2: I'm in the console. I click "Create Computer". The computer class form opens and it's empty. I put in a name. Then I click "Create related MyClass". That is _NOT_ allowed because the computer object does not yet exist.

So..before I go any further, do you want to use a console task to create a new in-memory item to relate to an existing item only? If yes, I'll write up some sample code on the CreateWithLinkHandler approach. If not, you'll need to put a button on your form to execute the code you've already written. Let me know :) I'll help you get this one worked out.

  • Marked as answer by Ro Ki Sunday, June 21, 2015 5:25 PM
Free Windows Admin Tool Kit Click here and download it now
June 20th, 2015 10:38pm

Hi Aaron,

I really appreciate your support & yes you are right, it "is" a not-so-easy-task to dig into the SDK and console API ...

Regarding your examples - my approach is based on example 1. I would like to create a relationship with an exisiting item. It should also be possible to fill in some predefined values and create the relationship "in the background" - so it would be great not having just an empty form ;)

Many thanks in advance

June 21st, 2015 12:48am

Hi Aaron,

using your keyword "CreateWithLinkHandler" I was able to do some search on TechNet/MSDN - and I found a similiar solution which I were able to adjust for my purpose  :)

So in the moment it looks like, that everything is working so far.

Once again - thanks for pointing me in the right direction!

Free Windows Admin Tool Kit Click here and download it now
June 21st, 2015 7:00am

Great! And you're welcome :)
June 21st, 2015 9:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics