User 0234
User 0234

Reputation: 145

Error occurred creating story: "Cannot parse object reference from", Rally

I am trying to create user stories in rally by java. Am failing to get response and it throwing " Cannot parse object reference from ".

Brief on my rally : Let assume I have Project name "Characters" and its has subs as A, B, C, D. I have to create my user stories in C. Is my following code correct in this prospect? Can anyone please help?

package samplerally;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.GetRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.util.Ref;

public class CreateStory {
public static void main(String[] args) throws URISyntaxException,IOException {

     String host = "https://rally1.rallydev.com";
     String username = "[email protected]";
     String password = "password";
     String wsapiVersion = "v2.0";
     String applicationName = "C";

 RallyRestApi restApi = new RallyRestApi(new URI(host),username,password);
 restApi.setWsapiVersion(wsapiVersion);
 restApi.setApplicationName(applicationName); 

    try {
        for (int i = 0; i < 3; i++) {

            // Add a story
            System.out.println("Creating a story...");
            JsonObject newStory = new JsonObject();
            newStory.addProperty("Name", "my story");
            newStory.addProperty("Project", "Characters");

            CreateRequest createRequest = new CreateRequest("hierarchicalrequirement", newStory);
            CreateResponse createResponse = restApi.create(createRequest);
            System.out.println("Response ::: "+createResponse.wasSuccessful());
            if (createResponse.wasSuccessful()) {

                System.out.println(String.format("Created %s",createResponse.getObject().get("_ref").getAsString()));

                // Read story
                String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
                System.out.println(String.format("\nReading Story %s...",ref));
                GetRequest getRequest = new GetRequest(ref);
            } else {
                String[] createErrors;
                createErrors = createResponse.getErrors();
                System.out.println("Error occurred creating story: ");
                for (int j = 0; j < createErrors.length; j++) {
                    System.out.println(createErrors[j]);
                }
            }
        }
    } finally {
        // Release all resources
        restApi.close();
    }
}
}

And I am getting error as :

Creating a story...
Response ::: false
Error occurred creating story: 
Could not read: Cannot parse object reference from "BSS HWSE Team Columbia"
Creating a story...
Response ::: false
Error occurred creating story: 
Could not read: Cannot parse object reference from "BSS HWSE Team Columbia"
Creating a story...
Response ::: false
Error occurred creating story: 
Could not read: Cannot parse object reference from "BSS HWSE Team Columbia"
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:"C:\Program Files\HP\Unified Functional Testing\bin\java_shared\classes";"C:\Program Files\HP\Unified Functional Testing\bin\java_shared\classes\jasmine.jar"

Please help. New to rally. Thanks in advance

Upvotes: 0

Views: 615

Answers (1)

nickm
nickm

Reputation: 5966

When setting reference fields such as Project, Iteration, Release, WorkProduduct, Parent, etc that point to full objects use the reference,and not the Name.

Find out the unique ObjectID of the Project "C", e.g. 123456.

Replace:

newStory.addProperty("Project", "Characters");

with

newStory.addProperty("Project", "/project/123456");

To find ObjectID of a project you may either query by its name in WS API, or look at the URL of one of Rally pages in the address bar, while in that project, e.g. URL of a Backlog page: https://rally1.rallydev.com/#/123456/backlog

If there is a d or u appended to ObjectID string, e.g. 123456d, do not include it in string. In the URL it indicates if you are currently scoping up or down.

Upvotes: 2

Related Questions