User security errors

I have been using the API to create new workorders and new workorder items to our database. Everything was working great, when I suddenly began to get errors on the administrative user profiles when trying to access existing work orders. I’ve been told that none of the admin profiles have been manually changed by our users, but the service began to return errors when it got to the command: ‘w = Workorder.GetItem(woID)’

one admin user returned: ‘Error: Current user not authorized to open a Workorder record’
I tried another admin profile and it returned: ‘Error.Security.NotAuthorizedToRetrieve’

Any ideas for a solution?

Thank you,


Hi Renah, the API is the exact same code that is used by the AyaNova program which also uses the API so the very first step always in diagnosing an issue like this is to try the same operation within the AyaNova user interface.

If you are fetching a workorder and that’s where you get the exception then it’s almost certain that you will get a similar error within the AyaNova program user interface and that someone has in fact made a change to a security setting, or your code is not running against the same database or there is a version mismatch between the api .dll’s you’re using in your code and the actual ones being used against that database.

I would recommend you run AyaNova using the exact same database (double check, it’s not unusual for people to be testing with one db and coding against another, double check that the version of the GZTW.AyaNova.BLL.dll file is the same between AyaNova that users are running against that db and the one your code uses), and login as the same user you are using in your code and try to retrieve the exact same workorder.

If it works in AyaNova in the user interface then it should work in your code.

Hello John,
I apologize for this delay in response. Thank you for your recommendations on this. I still seem to be getting the same errors. I verified the following:

  1. Using the same user login, I am able to open the same workorder directly in Ayanova with no problems.
  2. Both my code and Ayanova are using the exact same database.
  3. Both my code and Ayanova are using the exact same .dll version.

I’m also getting the “NotAuthorized” error with the command: “WorkOrder.NewItem(templateID, clientID)”

I tried creating a new administrator user to login, but I’m getting the same error. Since this error started occurring suddenly, is it possible that there could have been something that has damaged the database schema? I’ve never made a change to any data in the database without using the api or Ayanova…I have been very careful of this.

Let me know your thoughts. Thanks again!

Sounds like you have been very thorough.

Have no fear: there is nothing that you can do via the api or application that can damage the database schema. The only possible way to damage it is if there is a hardware failure at the exact moment that a new release is first run and auto updates the schema.

It’s certainly mystifying because AyaNova the program uses the exact same api you are using it’s not even different files, it’s the same files, same process to create a new workorder etc. If you are logged in successfully via the api then you have exactly the same rights as if you are using the user interface for that same user.

Which version of AyaNova do you have and have the latest hot fixes been applied?

When this suddenly stopped working was there anything unusual that happened at the time? (An update to anything, some environmental change to the O.S. or hardware?)

Can you provide a snippet of code (doesn’t have to be the whole thing) I can test here to confirm it’s not just some universal weirdness we haven’t run across before?

If you provide the above info I’ll try it here just to confirm your code should work and if it does work then we’ll need to replicate everything you have so we’d need your database and code to replicate here which can be sent through regular support. If it comes to that I’ll give you instructions.

We are using AyaNova version, hotfix 6.

License information:
Key issued: 3/1/2011 7:35:37 PM
Registered to: Energy Control
Version: 7.X
Scheduleable users: 1
Lite: False

Snippet of code:


        Dim lclients As ClientPickList = ClientPickList.GetList(False)
        Dim lTemplates As TemplatePickList = TemplatePickList.GetList(WorkorderTypes.Service, False)
        templateID = lTemplates.Item(1).ID

'variable iID represents a pre-determined client that the user selected from a list
clientID = lclients.Item(iID).ID

        AyaBizUtils.Login("adminuser", "temp")

'Below is where I’m getting the error*
WorkOrder = WorkOrder.NewItem(templateID, clientID)

Thanks’ Rena, we’ll try that out and see if we can replicate the error here.

Hi Rena just took a closer look at this, a couple of things:

Not entirely relevant but out of curiosity is this just for this sample or are you actually doing this because this line:

clientID = lclients.Item(iID).ID

Is redundant and effectively equal to


Aside from that I’m wondering why you are retrieving list info before you’ve logged in then logging in? There is no way to exactly replicate that in the user interface so you couldn’t test exactly the same thing in the UI as in your code for starters, but more importantly this doesn’t pass the “smell” test because it means you could have different rights from whatever original user you logged in as before you retrieve the template and client list than the user you are creating the workorder with, so for example if the first user could see all zones and the second user can’t you would run into problems.

Finally this line:
templateID = lTemplates.Item(1).ID
Is dangerous in that there is no guarantee there will be that item there for retrieval. My vb is fuzzy but if I recall correctly vb indexes are one based so you’re saying with that line give me the first template that comes back in that list. That’s non deterministic, you might not get the same template every time so I’m not sure why you’re doing that unless again it’s for the sample only and your original code isn’t at all like that.

Anyway, I’ll try to replicate the spirit of what you’re doing and see if it works here but that dual login thing tingles my spidey senses :slight_smile: , let me know your thinking with these items.

Replicated it and no errors so it’s not just a fundamental problem with the api, likely a combination of things unique to what you’re doing. I’ll await your reply on my last post and see what we can see from there.

Hi John,

Solution! You noted that I was grabbing the Client and Template guid’s before logging in. So…i moved around my login code to launch before the client and template code, and now it seems to be working! Guess I need to make sure that I login before taking any action at all upon the gztw.

I’ll let you know if the errors start coming up again. It seems odd that I never got these errors before until now, but hopefully this was the fix.

Sorry to take so much of your time…especially with such a simple solution, but I appreciate it. Thank you!


That’s great news Rena!
No worries, sometimes all it takes is another set of eyes.
To be honest I’m not sure how it was ever working for you because you shouldn’t be able to do anything at all without logging in first but as long as it’s working now that’s the main thing.


great thanks to both of you.i was also facing this kind of error and i got my solution after reading of your discussion.Thanks a lot