how to convert enum to string in contains function in xpath

0
Hi All I have a scenario where I need to retrieve data of enum attribute. In retrieve activity I had an Xpath which uses contains function.But contains function only supports string and I need to convert enum to string to use in contains but Xpath is not allowing to use toString/getKey to convert enum to string. Any suggestions on how to achieve this    
asked
3 answers
1

Hi Anvitha,

 

Before your retrieve activity , create string variable and define like below.

 

Consider your Enum attribute is Result which has values Pass & Fail.

 

The above attribute is in Student entity.

 

Add the below condition in your Create Variable activity and select data type as String

if($Student/Result=Exam.ENUM_Result.Pass)
then
'Pass'
else
‘Fail’

 

Now you have converted the Enum to String, Create one string variable in student entity itself for storing this enum converted to string value.

 

Use change object activity for updating student entity string attribute with your enumconvertedtostring value.

 

After this, you can use your string in your entity in contains function in xpath.

 

In this way you can convert Enum to String and use it in xpath contains function

answered
2

In the Xpath type

[YourAttributename=’

then press Ctrl-Space

then press arrow up

Now you can select from the list of your enumeration’s values.

If you know the exact enumeration-value that you want to use, then you can also just type it out directly, [YourAttributename=’yourvalue’]. A a typo is easily made, but StudioPro will give an error if the ‘yourvalue’ does not exactly match any of the enumeration’s keys.

answered
1

Hi Anvitha, 


Thank you for your question. I fully agree with Tim's answer. 

In the screenshots below, you can see how to do it in Studio Pro. 

 

Use case
We want to display all cars with a red color

 

Setup

 

Domain

 

Find all Cars with the Color Red

 

I am borrowing the steps described in Tim van Steenbergen's post for this.  (Thanks Tim 😉)

  1. Start typing  [Color='   in de XPath constraint field
  2. Press Ctrl-Space
  3. Press arrow up
  4. Select the enumeration value ‘Red‘ (’Red’)

 

Data source XPath

 

 

I hope my answer will help you 😊

 

Kind Regards,

Thomas Vansevenant

 

 

answered