xpath wont work when i use variables.

0
I get a user role into a variable , say $userrole (without single quotes  . “Roles” is a field on the entity on which data is being retrieved. now on the database retrieve i use the xpath syntax as  “ [contains(Roles,$userrole)]  this works fine, i am able to retrieve only the list which matches the user role. now, a user can be part of 2 or more roles, so i again put the data into variables, only this time the variable shows as below $userrole = role1’) or contains(‘role2’) or contains(‘role3 ( notice the single quote missed at beginning and end as xpath will fill them in.  . So the same xpath command does not work this time  ie ..[contains(Roles,$userrole)]  – this does not work but when i replace the variable manually into the xpath command and paste the xpath on the retrieve it works. ie [contains(Roles,’role1’) or contains(‘role2’) or contains(‘role3’)]   – this works what might be wrong here.. is xpath treating the variable differently..  
asked
6 answers
0

Likely you construct with the missing first and last missing brace will not work. Try comparing the association between User and UserRole against the UserRoleTokens the are available, like this XPath:

Directly after typing the

System.UserRoles=

press: Ctrl-Spacebar

followed by: arrow up

This takes to the bottom of the list, where the userrole tokens are.

 

answered
0

screenshot attached.

answered
0

Try this to see if this user has either of these roles. The screenshot of Tim was not quite correct.

Other way would be to retrieve the user roles of current user and use the find action to check if it has that user role.

Regards,

Ronald

 

answered
0

 

Unfortunately using attributes is not acceptable for xpath while using contains… so if variables are accepted there must be a way to make this work. i just need,  not to print '  when variable is passed, instead it should only print single quote..

answered
0

Attaching screenshot of what works and what does not, seeking help on this. Its inverted as the upload was stripping the image into half.

answered
0

i would have loved to have a solution to this in xpath itself. unfortunately i think i might be hitting some limitation of xpath. in case i am wrong and if anyone finds a solution please update.

so since this didnt work, i moved over to oql query statement, and it works perfectly fine there.

few things to note, when i constructed the whole of oql query into a variable and use it , it didnt work either.

so i put in the static section of the query into the oql statement and used a variable for the dynamic section.

that worked perfectly fine. with xpath im still using variable for dynamic section ,but it does not work at all.

anyways my problem is resolved by oql.

here is the query example

'SELECT C.Cluster as Cluster 
FROM Test.Cluster as C 
WHERE C.Roles LIKE '''+'%'+$oqlpatrialquery +''

the variable has following construction.

Role1%' OR C.Roles LIKE '%Role2%' OR C.Roles LIKE ‘%Role3%’

answered