Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
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
Solved! Go to Solution.
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
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
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