how to check whether a user have check in at the walkup interaction ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 05:37 AM
I would like some help. i have a widget but it does not work in validating whether the user have check in
server :
(function ($sp, options, input, data) {
var userId;
if (barCodeScanned(input)) {
var alm_hardware = new GlideRecord('alm_hardware');
alm_hardware.setLimit(1);
if (alm_hardware.get('serial_number', input.barCode)) {
if (!alm_hardware.assigned_to.nil()) {
userId = '' + alm_hardware.assigned_to;
var locationId = input.locationId;
// Enhanced logging
gs.info('Checking if user {0} has already checked in at location {1}', userId, locationId);
if (userAlreadyCheckedIn(userId, locationId)) {
data.error = gs.getMessage('User already has an open check-in at this location.');
gs.info('User {0} already has an open check-in at location {1}', userId, locationId);
} else {
data.interactionUniqueValue = lookUpAssetAndCreateInteraction(userId, input.barCode, locationId);
gs.info('Created new interaction for user {0} at location {1}', userId, locationId);
}
} else {
data.error = gs.getMessage('Assigned user not found for hardware with serial number: {0}', input.barCode);
gs.info('Assigned user not found for hardware with serial number: {0}', input.barCode);
}
} else {
data.error = gs.getMessage('Hardware record not found for serial number: {0}', input.barCode);
gs.info('Hardware record not found for serial number: {0}', input.barCode);
}
}
function barCodeScanned(input) {
return input && input.barCode;
}
function lookUpAssetAndCreateInteraction(userId, barCode, locationId) {
var facade = new sn_walkup.ExtPointUtil().loadExtension('InteractionFacade');
var reasonId = '253D84d50289479731107c2ba09f016d43f8';
var reasonDescription = 'Something not working';
var badgeId = true;
return facade.createInteraction(
userId,
locationId,
reasonId, // reasonID
reasonDescription, // reason description
false, // is_guest
'', // guest_name
'', // guest_email
false, // is_online_checkin
false, // is_appointment
badgeId ? true : false // is_badge_checkin
);
}
function userAlreadyCheckedIn(userId, locationId) {
var gr = new GlideRecord('interaction');
gr.addQuery('opened_for', userId);
gr.addQuery('location', locationId);
gr.addQuery('state', '!=', 'closed'); // Assuming 'closed' indicates an interaction is finished
gr.query();
var result = gr.hasNext();
if (result) {
gs.info('User {0} already checked in at location {1}. Existing interaction sys_id: {2}', userId, locationId, gr.sys_id);
} else {
gs.info('No existing check-in found for user {0} at location {1}', userId, locationId);
}
return result;
}
})($sp, options, input, data);
Client:
api.controller = function ($scope, spUtil) {
var c = this;
$scope.interactionUniqueValues = [];
$scope.runningRequests = 0;
// Initialize locations
spUtil.get('get_locations_widget', {
table: 'awa_queue'
}).then(function(response) {
c.locations = response.data.locations;
});
// The method on the $scope object needs to be created, because only stuff on the $scope object can be referenced in the Template HTML
$scope.handleCheckIn = handleCheckIn;
function handleCheckIn() {
// Set the transaction running flags - when higher then 0 the button will be disabled
$scope.runningRequests++;
// The framework takes care extracting the value from the input and of placing the value into property barCode of the widget's scope
var scannedBarcode = $scope.barCode;
var selectedLocationId = $scope.locationId;
// Execute the call to server side, passing in data to be used in the server script and doing something with the response
c.server
.get({
'barCode': scannedBarcode,
'locationId': selectedLocationId,
})
.then(makeCheckInHandled(scannedBarcode))
.finally(checkInFinally);
}
function makeCheckInHandled(barCode) {
return function checkInHandled(response) {
// Update the data in scope with new values received from the server
if (response.data.interactionUniqueValue)
$scope.interactionUniqueValues.splice(0, 0, {
'barCode': barCode,
'uniqueValue': response.data.interactionUniqueValue,
});
// Set or reset the "last" error message
$scope.scanError = response.data.error;
};
}
function checkInFinally() {
// Reset transaction running flags - when reaching 0 the button will be enabled
$scope.runningRequests--;
// Clear the barcode input
$scope.barCode = '';
}
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 03:33 PM
Hi @chercm ,
The ootb script by default check for the interaction if the user is already in the queue, if user is in the queue it will pop a message to the user that they are already in queue-
below eg. User(Abel Tuter) is already in the queue
Select Queue-
Now i am trying to check in again-
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar