Delete WHS Mobile Device Portal User Session in AX2012

To test the “new” WHS Mobile Device Portal in AX 2012 R3, one can use the WHSWorkExecute form (a nifty WMDP emulator). But while creating a new form inside the WMDP, I managed it to get stuck in a blank form, with no way out.
On top it seems like the actual session is saved in the WHSWorkUserSession table and even after logoff / logon the blank form comes up. So I created a small dialog to reset the user data, like in my post about creating a custom lookup.

TLDR: Delete the line realated to your WHSUserId in the WHSWorkUserSession table, to completly reset your user session.

First we create a new class which extends RunBase.

Declaration:

class WHSUserSession extends RunBase
{
DialogField fieldWHSUserId;
}
view raw WHSUserSession hosted with ❤ by GitHub

Methods:

Next we add a main method, create a new object of the class and call a method (resetUserSession()), which we will create in a second.

static void main(Args args)
{
WHSUserSession userSession = new WHSUserSession();
if (userSession.prompt())
userSession.resetUserSession();
}
view raw WHSDeleteUserSession hosted with ❤ by GitHub

Then we add the dialog() method where we get the WHSUserId and also getting the control to finally override the lookup().

The WHSUserId is the UserId we want to reset later.

protected Object dialog()
{
Dialog dialog;
FormStringControl control;
dialog = super();
dialog.caption("WHS: Reset user session");
  fieldWHSUserId = dialog.addField(extendedTypeStr(WHSUserId), "Select User");
control = fieldWHSUserId.control();
control.registerOverrideMethod(methodStr(FormStringControl, lookup),
methodStr(WHSUserSession, lookup), this);
return dialog;
}
view raw dialog hosted with ❤ by GitHub

Now we add the lookup to choose the UserId, I added the InventLocationId and the LastActionDateTime, to better distinguish the entries.
public void lookup(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(WHSWorkUserSession),
_control);
sysTableLookup.addLookupField(fieldNum(WHSWorkUserSession, UserId));
sysTableLookup.addLookupField(fieldNum(WHSWorkUserSession, InventLocationId));
sysTableLookup.addLookupField(fieldNum(WHSWorkUserSession, LastActionDateTime));
queryBuildDataSource = query.addDataSource(tableNum(WHSWorkUserSession));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
view raw lookup hosted with ❤ by GitHub

At least we add the resetUserSession(). We just use the value from the lookup and search the entry in the WHSWorkUserSession table, if we find a line, we are trying to delete the session and commit the changes.
private void resetUserSession()
{
WHSWorkUserSession workUserSession;
if (fieldWHSUserId.value())
{
workUserSession = WHSWorkUserSession::find(fieldWHSUserId.value(), true);
if (workUserSession)
{
try
{
ttsBegin;
if (workUserSession.validateDelete())
workUserSession.delete();
else
throw Exception::Error;
ttsCommit;
}
catch (Exception::Error)
{
error(strFmt("Could not delete user session data for userId %1",
workUserSession.UserId));
}
}
else
error(strFmt("UserId %1 not found!",
fieldWHSUserId.value()));
}
}
view raw resetUserSession hosted with ❤ by GitHub

Reset the WHS User Session in action:

This it what it looks like, if one hit OK, the WHS work user session will be deleted.
AX2012 WHS MDP Delet User Session

Advertisement

You may also like...