Defaulting String attributes to the current Users Name and Email address
In a users profile, a user has the userID, but also Name and Email address.
We have a custom work item that has two text fields:
Submitter Name
Submitter Email
We want to be able to default these values to the Name and Email from the logged-in user's profile. So by default, they are set to whomever is creating the work item (logged in). As the default, it would get put in initially but the logged-in user who is creating the work item could change it (scenario where I am typing in the work item by the real submitter is someone else).
Looking at DefaultValue providers, I can see that I can get the AuthenticatedUser, but it only allows me to get the entire Contributor, and I am not able to set that DefaultValue on my text fields (somewhat expected).
I then looked at a CalculatedValue, thinking I could calculate it *IF* they didn't enter something. I am trying to keep from making them required and making someone type in their name when I should be able to get their name from the user profile (same with email). I can do a Script-Based calculated value, but javascript APIs do not (I believe) give me access to the CurrentUser. That requires Java APIs. However, I can't find where I can link in a Java-based default value provider or a java-based CalculatedValue provider.
Can someone point me to this?
Susan
We have a custom work item that has two text fields:
Submitter Name
Submitter Email
We want to be able to default these values to the Name and Email from the logged-in user's profile. So by default, they are set to whomever is creating the work item (logged in). As the default, it would get put in initially but the logged-in user who is creating the work item could change it (scenario where I am typing in the work item by the real submitter is someone else).
Looking at DefaultValue providers, I can see that I can get the AuthenticatedUser, but it only allows me to get the entire Contributor, and I am not able to set that DefaultValue on my text fields (somewhat expected).
I then looked at a CalculatedValue, thinking I could calculate it *IF* they didn't enter something. I am trying to keep from making them required and making someone type in their name when I should be able to get their name from the user profile (same with email). I can do a Script-Based calculated value, but javascript APIs do not (I believe) give me access to the CurrentUser. That requires Java APIs. However, I can't find where I can link in a Java-based default value provider or a java-based CalculatedValue provider.
Can someone point me to this?
Susan
One answer
See
https://rsjazz.wordpress.com/2013/06/26/attribute-customization-java-based-value-providers-conditions-and-validators/ for how to use Java for providers.
You could use a default value provider to fill out the fields. Mixing a calculated value provider with manual input is actually problematic. It will always calculate when triggered. The only thing you can do is to pass the old value if there is one and pass a new value if there is no valid one. Usually attributes with calculated value providers should be set to read only in the UI, to avoid the user entering a value that gets eventually overwritten.
https://rsjazz.wordpress.com/2013/06/26/attribute-customization-java-based-value-providers-conditions-and-validators/ for how to use Java for providers.
You could use a default value provider to fill out the fields. Mixing a calculated value provider with manual input is actually problematic. It will always calculate when triggered. The only thing you can do is to pass the old value if there is one and pass a new value if there is no valid one. Usually attributes with calculated value providers should be set to read only in the UI, to avoid the user entering a value that gets eventually overwritten.