Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

help needed having issues in creating interactions in the walkup location queue.

chercm
Mega Sage

hi would need some help as i am having issue in getting the interactions created after scanning the serial number of the laptop using the service portal widget. i understand i need to use the facade function not sure is that true as i have tried to use the table method to create but it is not displaying in the correct walkuplocation queue 

 

interaction.initialize();
 
interaction.opened_for = alm_hardware.assigned_to;
interaction.location = alm_hardware.location; // Assuming 'location' is a field on the hardware table
interaction.reason = "Laptop refresh";
 
return interaction.insert();

 

(function ($sp, options, input, data) {
if (barCodeScanned(input)) {
var interactionSysId = lookUpAssetAndCreateInteraction(input.barCode);
if (interactionSysId) {
// Interaction successfully created, optionally perform additional actions
data.interactionSysId = interactionSysId;
} else {
// Handle the case where interaction creation failed
data.error = gs.getMessage('Failed to create a walk-up interaction.');
}
} else {
// Handle the case where the barcode is not scanned
data.error = gs.getMessage('Barcode not scanned.');
}
function barCodeScanned(input) {
return input && input.barCode;
}
function lookUpAssetAndCreateInteraction(barCode) {
var alm_hardware = new GlideRecord('alm_hardware');
if (alm_hardware.get('serial_number', barCode)) {
if (facade) {
var newInteraction = facade.createInteraction();
newInteraction.short_description = "Walk-up Interaction";
newInteraction.description = "Laptop refresh";
newInteraction.u_walkup_location = "Singapore"; // Update with the correct walk-up location
var interactionSysId = facade.saveInteraction(newInteraction);
if (interactionSysId) {
// Interaction successfully saved, optionally perform additional actions
facade.openInteraction(interactionSysId);
return interactionSysId;
} else {
// Handle the case where interaction save failed
gs.error("Error: Failed to save the walk-up interaction.");
return null;
}
} else {
// Handle the case where the facade is not initialized
gs.error("Error: Walk-up Interaction Facade not initialized.");
return null;
}
} else {
// Handle the case where the hardware record was not found
gs.error("Error: Hardware record not found for serial number: " + barCode);
data.error = gs.getMessage('Hardware record not found for serial number: {0}', barCode);
return null;
}
}
})($sp, options, input, data);

1 REPLY 1

chercm
Mega Sage

i tried to use this  and it is not working 

 

(function ($sp, options, input, data) {
if (barCodeScanned(input)) {
data.interactionUniqueValue = lookUpAssetAndCreateInteraction(input.barCode);
}
 
function barCodeScanned (input) {
return input && input.barCode;
}
 
function lookUpAssetAndCreateInteraction (barCode) {
var alm_hardware = new GlideRecord('alm_hardware');
alm_hardware.addQuery('serial_number', 'your_serial_number');
alm_hardware.query();
if (alm_hardware.next())
{
var userId = gr.assigned_to;
  gs.info(userId);
}
alm_hardware.setLimit(1);
 
 
 
if (alm_hardware.get('serial_number', barCode)) {
if (!alm_hardware.assigned_to.nil()) {
var facade = new sn_walkup.ExtPointUtil().loadExtension("InteractionFacade");
var queueId= "775bd4f62fd5b110207170682799b6c6";
var reasonId = "837468135b8b3300f6bc098b41f91ab8";
var reasonDescription ="Something not working";
var badgeId = true;
 
facade.createInteraction(
userId,
queueId,
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
 
);
 
}
else {
data.error = gs.getMessage('Assigned user not found for hardware with serial number: {0}', barCode);
}
}
else {
data.error = gs.getMessage('Hardware record not found for serial number: {0}', barCode);
}
}
})($sp, options, input, data);