0

I am building a Help Desk ticketing program in Lightswitch, and have been having trouble with one requested feature. I was asked to build a mobile friendly version of the app for End Users to submit tickets from their mobile devices. I built the app, with just a couple screens, and added code to the PreProcess query to limit the tickets they can see to only their own. That works wonderfully. What I'm having trouble with is assigning the currently logged in user as the submitter on a new ticket. I've looked at multiple guides online, all of which stop short at what I'm trying to do. The most promising I've found is http://social.msdn.microsoft.com/Forums/vstudio/en-US/47832659-4ed3-4a8c-9a62-b3ad46c8e8b4/get-logged-in-employee With that technique, I can succesfully display the current user on the screen.

The challenge is, setting the Ticket.EndUser field to the CurrentUserName field. I've tried it in the created method of the AddEditNewTicket screen, and the beforeApplyChanges method.

I've been bashing my head against this wall for a couple days now, has anybody out there ever accomplished this?


UPDATE

So, I think I may have found the problem, just not sure how to get around it. In the execute code for the new ticket button, I create the ticket, and use newTicket.setEndUser(). This function takes an EndUser entity as a parameter, so I retrieve it with myapp.activeDataWorkspace.MyDataBase.Techs_SingleOrDefault(CurrentUserName) which returns null. UserName is the primary key for my Techs table.

Even when I use a literal string for the UserName, it still returns null.

bigelowr
  • 431
  • 2
  • 11
  • I don't know if this will work on an HTML client, but I had the same problem with a desktop client. There at least, you can just put it in the Entity_Created method. 'EnteredByUser = Application.User.Name;' – Ethan48 Aug 12 '13 at 23:11
  • Well, I don't want to put it in the Entity_Created method on the server side, because that would then apply to all tickets created. If a technician enters a ticket, they would then be linked as the end user. – bigelowr Aug 12 '13 at 23:27
  • Entity_created on the client side might work, except I can't get to the screen.CurrentUserName property. – bigelowr Aug 12 '13 at 23:35

1 Answers1

0

Found it!

This forum post had the answer. http://social.msdn.microsoft.com/Forums/vstudio/en-US/dffe99ea-f12f-42e4-be14-7d5d04c2621f/entitytype-dataworkspaceapplicationdatatypessingleordefaultpr-in-javascript

I had to wrap the call get my tech or end user in a Promise Object, which gave me an array with the tech/end user I was looking for, so I had to get the first element of the array.

myapp.activeDataWorkspace.MyDatabase.Techs_SingleOrDefault(CurrentUserName).execute().then(function (result) {
 entity.setTech(result.results[0]);
});

Hopefully this will save some frustration for anybody trying to this in the future.

bigelowr
  • 431
  • 2
  • 11
  • Just a small technicality about the way you've phrased your sentence. You're not really "wrapping" your call in a _Promise_ object, the _execute()_ method **returns** a _Promise_ object. – Yann Duran Mar 14 '14 at 10:11