How to do CRUD operations on Custom Fields using Rally API?
Thanks for the clarification. Yes. It's possible. Let me walk you through this:
You will need to use WSAPI to create an AttributeDefinition. I suggest you use the WSAPI online documentation to learn all the fields of this object etc. There are three mandatory fields: Name, RealAttributeType and TypeDefinition which you must provide.
I used PostMan to create a custom field this way. In the screen shot below you see how I populated the three required fields:
Name - simple.
Real Attribute Type - corresponds to how this field will behave in Rally. I chose "STRING" for my example. Here is the list of your accepted types:
Type Definition - This needs to hold the structure of the Type Definition that matches the artifact you would like to associate your new custom field with. In my example that would be the Type Definition for Defect (which I queried to find).
When executed this above request, here is PostMan's response showing the details of the field that was created:
Let's also confirm that after you refresh the WSAPI doc, my field is showing under the Defect artifact:
Now, let's go check it out in Rally. Let's see it in the list of fields listed as a custom field under the project's Defect section:
And .. let's see that it's available for us to use when creating new defect in Rally under the Custom section:
I hope this helps answer your question in full.
Custom fields are named by a preceding "c_" , so for example if you have a custom field named: MyField then the true name is: "c_MyField". This is the Name of the field that you should use with the WSAPI when you query this field By Name. This way you can get the ObjectID of that field if you need it for further querying.
More generally, the WSAPI is used in the same way for custom fields like for the native fields. This means that you have a number of endpoints per your artifact and you need to use these endpoints in the exact same way.
You can learn more on that here:
Please let me know if you have further questions on that.
My requirement is to create, update and delete new custom fields not querying existing custom fields or query on existing custom fields.
API documentation talks what you mentioned but doesn't have a reference on how to create new custom fields.
Yes, I understand. Custom attribute are handled exactly the same like regular attributes with the API. Let me give you an example.
If you go to that link that I included for you previously then you'll see the WSAPI with the object model where you can test the CRUD queries. I prepared an example for you on the Defect artifact where I created a custom field named: "c_SagiSingledValued". The prefix "c_" is what's automatically added to all custom fields. So, let me show you how it works. In that page if you go to the Defect artifact you'll see:
This shows you the endpoints for each of your CRUD operations for Defect. So , let me walk you through testing it for a custom field. Here is my custom field:
Your custom fields show up in the list of fields of the artifact , along side the regular fields. So, in this case, if you scrolled a little down while on that page for Defect then you'll see all fields and one of them is this one.
So, now let's perform CRUD for this field:
This returns 3 defects which I have that meet this query, here is the result. Later on down the JSON response you will see all 3.
So, let's take one of these results and update it. To update, you can see in the above endpoint we need the ObjectID. Here it is:
So, let's do Update. For that I'll use PostMan (you can use any tool that allows you the use POST to that endpoint).
That worked, you can see it down at the body of the returned JSON, but you can also query that same defect again as earlier and you'll see the value was updated:
Now let's do Create:
I'll use PostMan again and make a PUT call to the create endpoint:
And I can see it was created with the correct name and value for my custom field:
And finally , let's Delete the defect we created:
We need the ObjectID of the defect, I'll take it from the JSON we just received for the created defect:
Now, let's delete the defect:
Return code is 200 (success):
As you can tell you work with a custom field in the same manner any other field.
I hope this is more clear. Please let me know if further questions.
Thanks for the detailed response.
However, my question was different. Let me clarify by using your example. Did you create "c_SagiSingledValued" field using API or Application? I am looking for API to create a custom field i.e. "c_SagiSingledValued" in your example.
I hope this is more clear. Please let me know if you have more questions.
Thanks for the detailed information, Sagi.
I tried within my workspace and it worked after following your steps.
I am also trying to implement the same using Rally SDK. Is there a way to create custom fields using Rally SDK?
Is there a way to delete custom fields using Rally API?
Glad I could help you.
About Deleting custom fields using Rally API:
No, you can't. In-fact you can't do that also with Rally's user interface. Custom fields can not be deleted. It's actually documented. If you need me to find the documentation , let me know. I believe the reason they can't be deleted is because they may be already in-use and referenced by many artifacts and so deleting a custom field necessarily requires to clear all references to it. So you can't delete a custom field with Rally API just as you can't delete it in any other way.
About creating custom fields using Rally SDK:
I am not sure about that. I can try it, hopefully in the next day/two and let you know. I'm quite certain it's not straight forward even if possible but I'll see if I can get it to work, I can't promise I will.
Just for my own curiosity: Why do you need/want to create custom fields using Rally SDK?
I also read it somewhere in the documentation that deleting custom fields is not possible. Let's not worry about deleting custom fields.
Our team wanted to explore other possible options which will help them in finalizing the option they want to go ahead with rest of automation.
Thank you Siva.
About deleting custom fields, as said, it's not possible, see the doc reference:
where says: "You cannot delete a field. Instead, edit the field while viewing the Fields summary from your workspace, and select No in the Visible (All Projects) drop-down.” - You may want to try that going-forward.
About the SDK:
Retrieving data ...