Thanks Sagi,
I referred that exact code. Below is the complete code i am using :
//Create a defect
System.out.println("Creating defect...");
JsonObject newDefect = new JsonObject();
newDefect.addProperty("Name", "Test Defect");
newDefect.addProperty("Project", "projectRef");
newDefect.addProperty("State", "Open");
newDefect.addProperty("ScheduleState", "Pending");
newDefect.addProperty("Environment", "Test");
newDefect.addProperty("Severity", "Cosmetic");
newDefect.addProperty("Priority", "Low");
newDefect.addProperty("Defect Reported By ", "Internally Reported");
//newDefect.addProperty("c_DefectReportedBy", "Internally Reported");
CreateRequest createRequest = new CreateRequest("defect", newDefect);
CreateResponse createResponse = restApi.create(createRequest);
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read defect
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading defect %s...", ref));
GetRequest getRequest = new GetRequest(ref);
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(String.format("Read defect. Name = %s, State = %s",
obj.get("Name").getAsString(), obj.get("State").getAsString()));
//Update defect
System.out.println("\nUpdating defect state...");
JsonObject updatedDefect = new JsonObject();
updatedDefect.addProperty("State", "Fixed");
UpdateRequest updateRequest = new UpdateRequest(ref, updatedDefect);
UpdateResponse updateResponse = restApi.update(updateRequest);
obj = updateResponse.getObject();
System.out.println(String.format("Updated defect. State = %s", obj.get("State").getAsString()));
---------------------------------------
But still i am getting -
CreateResponse createResponse = restApi.create(createRequest);{"CreateResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": ["Could not read: Object not found for Object ID: null"], "Warnings": ["It is no longer necessary to append \".js\" to WSAPI resources."]}}
Original Message:
Sent: 11-24-2020 03:22 PM
From: Sagi Gabay
Subject: i want to update a defect in Rally via Rally API.
Hi Anuj.
Please check out the java CRUD example file here, which is part of the Java toolkit. You need to instantiate the UpdateRequest object with a reference to the object (see the 'ref' variable). In your code you're replacing that with "DE170187". You'll need to locate the defect, fetch it and include its reference to your update request. I'm including a screenshot from that example page showing how it's done.
Please let us know if that helped.
Thanks,
Sagi
Original Message:
Sent: 11-23-2020 10:22 PM
From: Anuj Garg
Subject: i want to update a defect in Rally via Rally API.
I am able to pull/fetch the existing defects from Rally but not able to update the existing defect from Rally.
here is the code i am using :
//Update defect
System.out.println("\nUpdating defect state...");
JsonObject updatedDefect = new JsonObject();
updatedDefect.addProperty("State", "Fixed");
UpdateRequest updateRequest = new UpdateRequest("DE170187", updatedDefect);
UpdateResponse updateResponse = restApi.update(updateRequest);
JsonObject obj = updateResponse.getObject();
System.out.println(String.format("Updated defect. State = %s", obj.get("State").getAsString()));
-----------------
Error i am getting - in this line - UpdateResponse updateResponse = restApi.update(updateRequest);
Exception in thread "main" java.lang.NullPointerException: key == null
at com.google.gson.internal.LinkedTreeMap.put(LinkedTreeMap.java:92)
at com.google.gson.JsonObject.add(JsonObject.java:61)
at com.rallydev.rest.request.UpdateRequest.getBody(UpdateRequest.java:41)
at com.rallydev.rest.RallyRestApi.update(RallyRestApi.java:189)
at com.rallydev.rest.RallyRestApi.update(RallyRestApi.java:185)
at stepdefinitions.UpdateDefectRally.main(UpdateDefectRally.java:53)
Any suggestions please.