Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

[solved] Get a case ID from a test ID in UI scripts


#1

I am currently trying to write a UI script to automatically generate links to dashboards based on which tests in a run have their checkbox checked. I am able to successfully grab the test IDs of every line-item I’m trying to select but I’m having a difficult time getting the case ID instead. I know I can change the display to have a column for case ID but I cannot confirm that all of my users will have that column enabled. Is there any way to get a case Id from a test ID using only UI Scripts?

I use the following to get the test IDs:

var test_ids = App.Tables.getSelected($(’#groups’));

And this works fine, it’s just that the dashboards are built around case IDs and cannot be changed to accept test IDs.


#2

Solved this using the API via ajax:

var test_ids = App.Tables.getSelected($(’#groups’));

			for (var i = 0; i < test_ids.length; i++) 
			{
				$.ajax(
				{
					url: 'index.php?/api/v2/get_test/' + test_ids[i],
					dataType: 'json',
					beforeSend: function(xhr, settings)
					{
						xhr.setRequestHeader("Content-Type", "application/json");
					},
					success: function(data, status, xhr)
					{
						console.log(status);

						var case_id = data["case_id"];
						
					},
					error: function(xhr, status, error)
					{
						console.log(error);
						alert(error);
					}
				});
			}