cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Translate the entire conversation x

How to get an ID value of a pick filed selected?

AN_10548594
12-Amethyst

How to get an ID value of a pick filed selected?

Hello team,

How to get an ID value of a pick filed selected? getNewFieldValue() returns String value while need to get corresponding ID.

Thanks

ACCEPTED SOLUTION

Accepted Solutions

Solution is:


var fieldBean = bsf.lookupBean("imServerBean").getFieldBean(categoryFieldName);
var fieldMap = fieldBean.getPickFieldMappings();
print("=>>>> fieldMap is : " + fieldMap);
var newValue = delta.getNewFieldValue(categoryFieldName);
print("=>>>> newValue is : " + newValue);
var newValueInt = fieldMap.get(newValue);
print("=>>>> newValueInt is : " + newValueInt);

 

View solution in original post

5 REPLIES 5

You have to explain your question a little bit better. Have you tried it, and what error did you get? Is it for a JavaScript trigger or different language? Can you show a piece of your code?

If it's JavaScript, it's pretty much data type independent and I think that if you do something like this, it works without data transformation:

var sb = bsf.lookupBean( "imServerBean" );

// plus code to get the delta bean in variable "ib"

var selectedID = ib.getNewFieldValue( "myPickFieldName" );

var selectedBean = sb.getIssueBean( selectedID );

Otherwise, you can use the JavaScript function parseInt.

Hello pal,

This is what I have:

 - a field of type pick (1-red, 2- blue, 3 - green) at SharedRequirement level;

- a field of type FVA tied to this pick field at Requirement level with constrains to these values; (same allowed values 1,2,3) do I need this picks-fva pattern to use?

may be having picks field defined directly at Requirement level is ok for my case?

- selecting a drop down menu with values red-blue-green gives me "red"\"blue"\"green" string if use getNewFieldValue();

but I need to transform it to 1\2\3 somehow....

may be need to use direct picks field instead of FVA that tied to picks?

Regards,

 

 

 

I see, this is related to the other post I started replying to. I'll give you more details as soon as my work duties allow, probably within the next couple days.

For this one, you didn't answer my questions and the use case is still pretty unclear. At first glance, I'd say yo don't need to write code for that.

 

This is my simple code to check it things.

 

function print(s)
{
    java.lang.System.out.println(s);
}
 
var categoryIntFieldName = "mnpkCategoryInt";
var categoryFieldName = "mnpkCategory";
var sharedCategoryFieldName = "mnpkSharedCategory";
 
 
var eb = bsf.lookupBean("siEnvironmentBean");
var sb = bsf.lookupBean("imServerBean");
var delta = bsf.lookupBean("imIssueDeltaBean");
var fieldBean =  bsf.lookupBean("imServerBean").getFieldBean(categoryFieldName);
 
// Header category hardcoded number is  '20'
 
main();
 
function main() {
print("=>>>> Trigger reqSyncCategoryField.js invoked");
print("=>>>> fieldBean.getFVARelationship() is : " + fieldBean.getFVARelationship()); 
print("=>>>> fieldBean.getFVAField() is : " + fieldBean.getFVAField());
 
var newRefDelta = sb.getIssueBean(delta.getNewReferences());
 
print("=>>>> delta.getNewReferences() is : " + newRefDelta);
print("=>>>> newRefDelta.getFieldValue is : " + newRefDelta.getFieldValue(sharedCategoryFieldName));
 
print("=>>>> mnpkCategoryInt is : " + delta.getFieldValue(categoryIntFieldName));
print("=>>>> mnpkCategory is : " + delta.getNewFieldValue(categoryFieldName));
//delta.setFieldValue("Category", 20);
}
 
 
and here is the output:
short explanation - selected FVA entry is "Requirement" (last string of out) and its pick ID is 1 (what I need to get).
using code that traverses fva-pick pattern I can get this number but it's for old\stored in database value of 2 (that corresponds to pick value called "Information").
So two ways left to get what I need:
- get correct ID from new selected FVA field value using some other code
- find a way to get correct ID from returned string part of pick definition pair
 
 
2025-05-12 22:18:11,604 INFO [STDOUT] =>>>> Trigger reqSyncCategoryField.js invoked
2025-05-12 22:18:11,620 INFO [STDOUT] =>>>> fieldBean.getFVARelationship() is : References
2025-05-12 22:18:11,620 INFO [STDOUT] =>>>> fieldBean.getFVAField() is : mnpkSharedCategory
2025-05-12 22:18:11,620 INFO [STDOUT] =>>>> delta.getNewReferences() is : imIssueBean: ID 8187 of type SharedRequirement
2025-05-12 22:18:11,620 INFO [STDOUT] =>>>> newRefDelta.getFieldValue is : Requirement
2025-05-12 22:18:11,620 INFO [STDOUT] =>>>> mnpkCategoryInt is : 1
2025-05-12 22:18:11,620 INFO [STDOUT] =>>>> mnpkCategory is : Information
2025-05-12 22:18:25,479 INFO [STDOUT] =>>>> Trigger reqSyncCategoryField.js invoked
2025-05-12 22:18:25,479 INFO [STDOUT] =>>>> fieldBean.getFVARelationship() is : References
2025-05-12 22:18:25,479 INFO [STDOUT] =>>>> fieldBean.getFVAField() is : mnpkSharedCategory
2025-05-12 22:18:25,479 INFO [STDOUT] =>>>> delta.getNewReferences() is : imIssueBean: ID 8187 of type SharedRequirement
2025-05-12 22:18:25,495 INFO [STDOUT] =>>>> newRefDelta.getFieldValue is : Information
2025-05-12 22:18:25,495 INFO [STDOUT] =>>>> mnpkCategoryInt is : 2
2025-05-12 22:18:25,495 INFO [STDOUT] =>>>> mnpkCategory is : Requirement

 

Solution is:


var fieldBean = bsf.lookupBean("imServerBean").getFieldBean(categoryFieldName);
var fieldMap = fieldBean.getPickFieldMappings();
print("=>>>> fieldMap is : " + fieldMap);
var newValue = delta.getNewFieldValue(categoryFieldName);
print("=>>>> newValue is : " + newValue);
var newValueInt = fieldMap.get(newValue);
print("=>>>> newValueInt is : " + newValueInt);

 

Announcements


Top Tags