Skip to main content
1-Visitor
Mar 24, 2015 1:34 AM UTC
Solved

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-Visitor
Jun 11, 2015 8:57 PM UTC

9 replies

1-Visitor
Mar 31, 2015 7:04 PM UTC

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

Translate
16-Pearl
Apr 1, 2015 6:56 AM UTC

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

Translate
1-Visitor
Apr 1, 2015 4:56 PM UTC

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

Translate
nborrerojr.1-VisitorAuthorAnswer
1-Visitor
Jun 11, 2015 8:57 PM UTC
1-Visitor
Jun 24, 2015 4:48 PM UTC

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();

Translate
1-Visitor
Jun 24, 2015 4:56 PM UTC

I forget to include the environmentBean!

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

Translate
1-Visitor
Jun 24, 2015 7:38 PM UTC

That is a great solution. Thank you for sharing!

Translate