New in the Community? Get started here

Schneider Electric Exchange Community

Discuss and solve problems in energy management and automation. Join conversations and share insights on products and solutions. Co-innovate and collaborate with a global network of peers.

Register Now
Geo SCADA Expert Forum
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Lt. Commander

[import] SQL Unknown Element

>>Message imported from previous forum - Category:Scripts and Tips<<
User: dialvec, originally posted: 2019-02-28 20:35:48 Id:372
Hi.

I wrote this script to check if curent user has admin clearance

Function VerifyUser()

Dim oQuery 'SQL Query to get all users
Dim oQueryRows 'Rows of OQeury result
Dim oMasterGroup 'Object for 'Admin' UserGroup
Dim oCurrentUser 'Object for current user
Dim sCurrentUser 'User requesting station creation

sCurrentUser = Server.Username

'Gets the UserGroup 'Admin' object
Set oQuery = Server.Query("SELECT Fullname FROM CDBUserGroup WHERE Fullname like '%Full'") 'SQL Query
oQueryRows = oQuery.Rows 'Gets the Fullname into a nxn matrix
Set oMasterGroup = Server.FindObject(oQueryRows(0,0)) 'GetS Admin UserGroup object


'Gets fullname of
Set oQuery = Server.Query("SELECT UserGroupNames FROM CDBUser WHERE Name = '" & sCurrentUser & "'") 'SQL Query
oQueryRows = oQUery.Rows 'Contains al the user groups that current user belongs to.
msgbox oQuery.ErrorMessage
Set oCurrentUser = Server.FindObject(oQueryRows(0,0)) 'Gets Current User object

if oCurrentUser.Interface.UserGroupIds = oMasterGroup.Id Then
VerifyUser=1

Else
MsgBox "Error: El usuario actual no tiene permisos de administrador.", vbOKOnly+vbExclamation, "Error"
VerifyUser=0
End if

end Function

 

But when executing, it gives me the following message:
ExecuteQuery failed: Unknown element

 

I already reviwed syntaxis and found no mistakes

Any suggestion?

Thank you


Reply User: sbeadle, posted: 2019-02-28 21:14:29
Server.FindObject is probably the source of the error. You are passing it a string array, as UserGroupNames is an array. You may want to loop through its members.

Looking at what you are trying to do, why not use the CheckAccess function to see if the user (and therefore group membership) is authorised?