Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top