Question

I am working with an SDK that can query a set of data as well as update data with a restful web service called VersionOne. We use the web service to document QA testing. Each test has attributes such as "Name", "Status", etc. Most of the attributes have been successfully updating except for "Status".

Here is the method I am calling, when I step through the code I can get the old value but cannot change the attribute value as expected. An error stating "Cannot assign new value to a read-only attribute".

public bool TestInProgress()
    {
        var testId = Oid.FromToken("Test:26017", _context.MetaModel);
        var query = new Query(testId);
        var assetType = _context.MetaModel.GetAssetType("Test");
        var testStatus = assetType.GetAttributeDefinition("Status.Name");

        query.Selection.Add(testStatus);
        var result = _context.Services.Retrieve(query);
        var test = result.Assets[0];
        var oldResult = GetValue(test.GetAttribute(testStatus).Value);
        test.SetAttributeValue(testStatus, "Failed");
        _context.Services.Save(test);

        LogResult(test.Oid.Token, oldResult, GetValue(test.GetAttribute(testStatus).Value));
        Console.WriteLine(test.Oid.Token, oldResult, GetValue(test.GetAttribute(testStatus).Value));

        return true;

    }

https://github.com/versionone/VersionOne.SDK.Net.APIClient#attribute-definition

According to the VersionOne SDK documentation it appears as though "read-only" and is an attribute. I've looked though the different attribute from several different tests and testsets and do not see it. I am authenticated properly and have successfully updated other attributes with many different tests. However, when I attempt to programmatically change the "Status" attribute it says it is read-only.

https://github.com/versionone/VersionOne.SDK.Net.APIClient#learn-by-example-apiclient-setup

How do you change the attribute for an asset in VersionOne programmatically that is currently read-only so you can update the attribute using the restful web service?

Was it helpful?

Solution

Because the Attribute is read-only, you will not be able to change its value. Instead, consider creating a 'new' Asset, set its Attributes, and then save it.

Review the example below and attempt to utilize the idea within your project:

var TestId = Oid.FromToken("Test:26017", _context.MetaModel);
var TestAsset = _context.MetaModel.GetAssetType("Test");
var newTestAsset = _context.Services.New(TestAsset, TestId);

var TestStatusAttr = newTestAsset.GetAttributeDefinition("Status.Name");
newTestAsset.SetAttributeValue(TestStatusAttr, "Failed");
_context.Services.Save(newTestAsset);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top