Absent Member.
Absent Member.
1733 views

Sorting Attribute values via API

Jump to solution

Hi,

I have an attribute of type "list" (single not multi select) with about a few hundred items. These items were imported from a different tool and unfortunately not sorted before the import. Now I want to sort the values alphabetically without affecting the test cases that already have this attribute attached. The items do not have a numeric weight.

As rearranging such a long list is more than painful with the GUI, I try to do this via API.

In general the tmplanning service seems to offer this functionality: like updateNote (which worked for me in other scripts) there is also an updateAttribute function. Unfortunately this function does not report an error but also does not change anything. I tried to rearrange existing attribute items, rename existing attribute items or even add new items (which is normally done with a different API function) with it, but nothing happened.

I use the powershell to call the functions and it is basically this sequence:

$attrList = $tmPlanningService.getAttributes($sessionId, $projectId)
$cat = $attrList |Where-Object { $_.name -eq "myattribute" }
$temp = $cat.options |Sort-Object name
$cat.options = $temp
$myattr = @($cat)
$tmPlanningService.updateAttributes($sessionId, $projectId, $myattr)

The last function call returns the "updated" attribute just like the function description says, containing my modified values, but the GUI still contains the old ones.

I tried also the function "getAttributesWithOptionValues" but it seems to be buggy, as it only works for projectId = 0 (which is the Demo Project on my server):

[DBG]: PS D:\>>> $tmPlanningService.getAttributesWithOptionValues($sessionId, 0)

active            : True
description       :
id                : 62
name              : Importance
optionsWithValues : {Critical, High, Medium, Low}
type              : normal

[DBG]: PS D:\>>> $tmPlanningService.getAttributesWithOptionValues($sessionId, $projectId)
Ausnahme beim Aufrufen von "getAttributesWithOptionValues" mit 2 Argument(en):  "java.rmi.RemoteException: null; nested exception is:
    java.lang.NullPointerException"
Bei Zeile:1 Zeichen:49
+ $tmPlanningService.getAttributesWithOptionValues <<<< ($sessionId, $projectId)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
 


Anyone has an idea what I do wrong or if there is another way to achieve this?

I'm using SCTM 15.5.

thanks for any help,

Wolfgang

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Hi Wolfgang,

Updating attribute options via web service interface is not supported. This would be an enhancement.

Regards,

Hubert

View solution in original post

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

Hi Wolfgang,

Updating attribute options via web service interface is not supported. This would be an enhancement.

Regards,

Hubert

View solution in original post

0 Likes
Absent Member.
Absent Member.

Thanks for the answer.

Then I guess I have to write a script to create a second attribute, fill it with the sorted values from the first attribute, attach the new attribute to all testcases that use the first attribute and rename the attributes.

Cheers,

Wolfgang

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.