API call to sort a custom field | Community
Skip to main content
Level 4
October 21, 2022
Solved

API call to sort a custom field

  • October 21, 2022
  • 1 reply
  • 1364 views

Hi all, I have figured out how to add a parameter to a custom field via a API call, but now I would like to sort the field to be in alphabetical order.  This is what I have for the adding of a new value:

https://mydomain.sb01.workfront.com/attask/api/v15.0/POPT?value="ABC"&parameterID=5a0a7b3401815c9b9cd8ed5b0aa7d276&label="ABC" with a POST command.

 

Do I need a PUT command to sort the whole parameter or is it to the parameter group? And if you use displayOrder, what is the value? displayOrder=??? it needs to be a integer.

 

Any assistance would be greatly appreciated.  Thanks, Mollie

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by William

Hi Mollie, 

1. Parameter Group refers to Custom Form Sections, so that's unrelated to your current challenge. 
2. Display Order refers to the order in which the Parameter Options are listed. 1 is first, 2 is second, etc. 

To my knowledge there is no API endpoint or syntax that will alphabetize the Parameter Options for you. In the UI, checking that box while editing a dropdown field reorders the list using JavaScript, not an API call. The API call that is sent to Workfront when saving the custom form informs Workfront that it should set a new order for the Parameter Options of the dropdown field, but it's not a simple "alphabetize this list" command - it says "set the display order of Alpha to 1. set the display order of Beta to 2. set the display order of Charlie to 3." and so on. 

To do this action via API, your script or scenario that is sending the API command to Workfront should POST the new Parameter Options, then GET them all from the Parameter, then use its own logic to alphabetize the list, then set the new display order values accordingly, then PUT those updates with the new display order back to Workfront . 

Honestly it's probably not worth the amount of effort needed to code the function, unless you need to do this to hundreds of fields.  

 

If anyone knows a secret unpublished endpoint that performs this action, I'm interested to know it!

1 reply

William
Community Advisor
WilliamCommunity AdvisorAccepted solution
Community Advisor
October 21, 2022

Hi Mollie, 

1. Parameter Group refers to Custom Form Sections, so that's unrelated to your current challenge. 
2. Display Order refers to the order in which the Parameter Options are listed. 1 is first, 2 is second, etc. 

To my knowledge there is no API endpoint or syntax that will alphabetize the Parameter Options for you. In the UI, checking that box while editing a dropdown field reorders the list using JavaScript, not an API call. The API call that is sent to Workfront when saving the custom form informs Workfront that it should set a new order for the Parameter Options of the dropdown field, but it's not a simple "alphabetize this list" command - it says "set the display order of Alpha to 1. set the display order of Beta to 2. set the display order of Charlie to 3." and so on. 

To do this action via API, your script or scenario that is sending the API command to Workfront should POST the new Parameter Options, then GET them all from the Parameter, then use its own logic to alphabetize the list, then set the new display order values accordingly, then PUT those updates with the new display order back to Workfront . 

Honestly it's probably not worth the amount of effort needed to code the function, unless you need to do this to hundreds of fields.  

 

If anyone knows a secret unpublished endpoint that performs this action, I'm interested to know it!

If you like my content, please take a moment to view and vote on my Idea Requests: https://tinyurl.com/4rbpr7hf
MollieShAuthor
Level 4
November 14, 2022

Hi,

 

So I've gotten as far as getting the new list, sorting it and updating the display order.  The problem is I can't figure out the PUT command to replace the display order.  Any help would be appreciated, we add a new item to this list about once a week, so it would be really nice to have it sorted.

 

And actually I've noticed that when posting new names to the list if I don't do the manual sort in Workfront the api call POSTs the new values in alpha order, but only the new ones.  Thanks, Mollie