cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

How do we setup a relationship to an item in a pre-trigger script?

smccoy
12-Amethyst

How do we setup a relationship to an item in a pre-trigger script?

Hi.

This has turned out to be a more complex transaction than it should be. This is done in Integrity with "Create Related Item", so we know that what we're trying to do is possibleon some level.

What we need to do...

From a pre-trigger that is invoked on a state-change of an item, we are automatically creating a bunch of "child items". In other words, creating several items that have a relationsip with the item whose state has just been changed. The creation is working perfectly, with one exception. And that exception is the creation of the relationship back to the parent. If we leave that out, items get created. If we keep it in, we get an error message that is:"MKS5380160: The item you are attempted to edit is currently locked by another edit. Please try again later."

Since relationships are added to an item being edited by the "Create Related Item" functionality, how do we accomplish the same functionality with this automated creation process that we've created.

The code that works:

function CreateTestCaseResult(aTestCaseResultDescription, parentTestSessionID, parentTestCaseID )

{

var cmd = new Packages.com.mks.api.Command("im","createissue");

var description = "Test Result Description=" + aTestCaseResultDescription;

var testSessionforTestCaseResult = "Test Session for Test Case Result=" + parentTestSessionID;

var testCaseforTestCaseResult = "Test Case for Test Case Result=" + parentTestCaseID;

cmd.addOption( new Packages.com.mks.api.Option("type", "Test Case Result") );

cmd.addOption( new Packages.com.mks.api.Option("field", description));

//cmd.addOption( new Packages.com.mks.api.Option("field", testSessionforTestCaseResult));

cmd.addOption( new Packages.com.mks.api.Option("field", testCaseforTestCaseResult));

var response = api.executeCmd(cmd);

}

The code that does not work:

function CreateTestCaseResult(aTestCaseResultDescription, parentTestSessionID, parentTestCaseID )

{

var cmd = new Packages.com.mks.api.Command("im","createissue");

var description = "Test Result Description=" + aTestCaseResultDescription;

var testSessionforTestCaseResult = "Test Session for Test Case Result=" + parentTestSessionID;

var testCaseforTestCaseResult = "Test Case for Test Case Result=" + parentTestCaseID;

cmd.addOption( new Packages.com.mks.api.Option("type", "Test Case Result") );

cmd.addOption( new Packages.com.mks.api.Option("field", description));

cmd.addOption( new Packages.com.mks.api.Option("field", testSessionforTestCaseResult));

cmd.addOption( new Packages.com.mks.api.Option("field", testCaseforTestCaseResult));

var response = api.executeCmd(cmd);

}

-Sean

ACCEPTED SOLUTION

Accepted Solutions
smccoy
12-Amethyst
(To:mrump)

Hi Matthias,

Thanks for the reply. I'm taking a different approach to this. Instead of trying to establish the relationship as the item is created. I'm creating the item, and adding the relationship to the parent item afterward.

-Sean

View solution in original post

2 REPLIES 2
mrump
16-Pearl
(To:smccoy)

Hi Sean,

from a first look I assume that you try to apply a newly created Item to the relationship field "testSessionforTestCaseResult"; correct ?

If you do so, you should always identify the item by it's ID.

Your code:

...

var testSessionforTestCaseResult = "Test Session for Test Case Result=" + parentTestSessionID;

...

cmd.addOption( new Packages.com.mks.api.Option("field", testSessionforTestCaseResult));

...

adds a new empty field, with a "dynamic" name ("Test Session for Test Case Result=" + parentTestSessionID).

I doubt this was your intention.

HTH Matthias

smccoy
12-Amethyst
(To:mrump)

Hi Matthias,

Thanks for the reply. I'm taking a different approach to this. Instead of trying to establish the relationship as the item is created. I'm creating the item, and adding the relationship to the parent item afterward.

-Sean

Announcements


Top Tags