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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Test Result Modified Date

nborrerojr.
7-Bedrock

Test Result Modified Date

How do I access the "Test Result Modified Date" value from a trigger? The value I'm referring to is in the below image.

 

TestSession.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
9 REPLIES 9

I still haven't been able to figure this out. Is this possible?

mrump
14-Alexandrite
(To:nborrerojr.)

Hi Nolin,

I would try to use the ScriptTestResultBean 's method

public java.lang.Object getFieldValue(java.lang.String fieldName)

so in a script something like:

....

// get the server

var serverBean = bsf.lookupBean("imServerBean");

// some Helpers

var aSimpleDateFormat= params.getParameter("dateFormat Field");

var formater = new java.text.SimpleDateFormat(aSimpleDateFormat);

// get your testsession by issueID

var sessionBean = serverBean.getIssueDeltaBean(issuesID);

// get your test results array

var allresultsArray = sessionBean.getRelatedTestResultBeans();


// get Modified Date of the first test result

if (allresultsArray[0] != null){

var modDate = allresultsArray[0].getFieldValue ("Test Result Modified Date");

if (modDate != null){

if (modDate instanceof java.util.Date ){

Packages.mks.util.Logger.message("GENERAL", 0, " First Result modified on : " + formater.format(modDate ));

}

}

}



HTH Matthias

I get Not Found when I try to use Test Result Modified Date. The trigger runs when the Test Session is moved to the ALM_Completed state.

var delta = bsf.lookupBean("imIssueDeltaBean");

var resBean = delta.getAssociatedSessionTestResultBeans();

resBean[i].getFieldValue("Test Result Modified Date"); // This is used in a loop in the trigger

I just tried using delta.getRelatedTestResultBeans() as well but it gives the same result of Not Found.

errorMessage.jpg

mrump
14-Alexandrite
(To:nborrerojr.)

Hi Nolin,

I really think you should escalate this to PTC Support.

As testresults are technically not the same as other item types in IM, there is a good chance that the feature you request either

- does not exist,

- has a bug, or

- is so missleadingly described that we both have not chance to find out how it's supposed to work.

IMHO there is a good change that the displayed field name "Test Result Modified Date" is either not the correct database field name (which would explain the error message),

or that it is nor "real" field at all (comparable to the "section" field in the document model) that cannot be accessed by the ".getFieldValue(<fieldname>)" method anyway.

Anyhow, I think this cannot be solved without help from PTC.

HTH Matthias

Ok, will do. Thank you for the help Matthias!

Here is how I get around it...by using the API.  I'd rather not have to go to the API to get something that should be available in the BSF, but you have to do what you have to do.

// Main

function main()

{

  API.Session   = eb.createAPISessionBean();

  API.CmdRunner = API.Session.createAPICommandRunnerBean();

  var resultObject = getTestResultModifiedDate(put sessionId here, put testId here);

}

function getTestResultModifiedDate(sessionId, testId)

{

  var args =

  [

  [ "tm"           , "results"      ],

  [ "sessionID"    , sessionId      ],

  [ "fields"       , "modifiedDate" ],

  [ "selection"    , testId         ]

  ];

  var response = API.execute(args);

  var results  = {};

  // Generate return object, in this case there is just one result (workItem)

  // So the loop is a bit overkill

  var workItems = response.getWorkItems();

  while (workItems.hasNext())

  {

  var workItem = workItems.next();

  var results.modifiedDate = java.util.Calendar.getInstance();

  results.modifiedDate.setTime(java.util.Date(workItem.getField(resultFld).getDateTime()));

  }

  return results;

}

// API

//*********************************************************************************

var API =

{

  Session   : false,

  CmdRunner : false,

  execute : function (args)

  {

  var cmdName = "";

  var total   = args.length;

  API.CmdRunner.resetOptions();

  API.CmdRunner.resetSelection();

  for (var i = 0; i < total; i += 1)

  {

  print("args[" + i + "]: " + args[i]);

  if (i === 0)

  {

  cmdName = args[i][1];

  API.CmdRunner.setCommand(args[i][0], cmdName);

  }

  else if (String(args[i][0]) === "selection")

  {

  API.CmdRunner.addSelectionElement(args[i][1]);

  }

  else if (args[i].length == 1)

  {

  API.CmdRunner.addOption(args[i][0]);

  }

  else if (args[i].length == 2)

  {

  API.CmdRunner.addOption(args[i][0], args[i][1]);

  }

  }

  // Invoke the command through the API using the default API credentials from is.properties

  var response = null;

  var exitcode = 0;

  try

  {

  response = API.CmdRunner.execute();

  exitcode = response.getExitCode();

  if (exitcode != 0)

  abort("The " + cmdName + " command failed with exit code: " + exitcode);

  }

  catch (re)

  {

  var errtxt = "Exception thrown while executing " + cmdName + " command.  Exception message: " + re.message;

  abort(errtxt);

  }

  return response;

  }

};

main();

dpayne
1-Newbie
(To:dpayne)

I forget to include the environmentBean!

var eb            = bsf.lookupBean('siEnvironmentBean');

That is a great solution. Thank you for sharing!

Top Tags