ERROR 5540 - User "UnknownUser" is not privileged for the operation.
This tells me that you don't login with a managed user with enough privileges.

So you could have a dedicated user just for this purpose.
OR
give "Unknown User" enough rights
OR
make use of a Privileged Application to assign temporary required Resources (my guess "%Developer") 

more on this and pp.
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.PortalHelpPag...

Hi Ken,

There is an easier way.

Instead of fiddling around with unpredictable params you just pass your whole symbol table = local variables
to your background job like this and use what you need in background

JOB ##class(%SYSTEM.OBJ.FM2Class).All():(:1):5

look for process-params + switch  here
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

Evgeny,

in SQL you have a CASE ... END block for selection

http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

CASE 
  WHEN search_condition THEN value_expression
  [ WHEN search_condition THEN value_expression ... ]
  [ ELSE value_expression ]
END

CASE value_expression
  WHEN value_expression THEN value_expression
  [ WHEN value_expression THEN value_expression ... ]
  [ ELSE value_expression ]
END

That's fine and nothing new.
You missed my point:

With the Class Query it's not self explaining if params got to Prepare() or to Execute()
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?P...

I just learned from  John Murray a few comments above

Prepare() is for dynamic SQL, but in your case it's a class query you want to run.
So change your rs.Prepare call to be an rs.Execute one.


that you don't need a prepare with a Class Query.
I wasn't aware of that until a few hours ago.

Then it's obvious that any param has to go to Execute().

If the owner of a table is _PUBLIC, users do not need to be granted object privileges to access the table.

http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

based on that you can build an OWNER that has also limited rights (only SELECT, REFERENCES, .. or whatever) 

So you do it for this Owner only

As you said all are unique

I try to summarize it simple:
IDkey is used in storing object s. Best to be translated : Global subscript of data store.
Could be defaulted to %Integer >0

Unique key defines an index with unique values of a property in parallel to IDkey. Checked during object save.

PrimaryKey comes from SQL world and could be interpreted  mostly as a synonym to IDkey
 

ENSDEMO>d $system.SQL.Shell()
SQL Command Line Shell
----------------------------------------------------
 
The command prefix is currently set to: <<nothing>>.
Enter q to quit, ? for help.
ENSDEMO>>select * from Ens_Config.Credentials
1.      select * from Ens_Config.Credentials
 
ID      BusinessPartner PasswordObject  Password        SystemName      Username
 
.... Rows(s) Affected