Mobile Agent - Action Item Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2019 07:36 AM
I need help in creating a Action Item Script to use on the Mobile Agent App.
Purpose of the App is for our Procurement Group to scan newly arrived hardware and update the cmdb_ci_computer table. – Single or Pallets of Hardware
Function I need are:
- Save the PO Number so it will not have to be re-keyed each time, but also able to change when the PO number changes
- Validate the Name and/or the Serial number has not been saved already into the cmdb_ci_computer
The fields that are captured or preset to a value are the following:
Name
PO Number - Value Set to Previous used / or able to be Changed
Model Number
Serial Number
Support Staff – Value Set to Desktop Services
Hardware Status – Value Set to In Stock
MAC Address
(function WriteBackAction(input) {
// Create New Computer Record
var gr = new GlideRecord('cmdb_ci_computer');
gr.initialize();
gr.setValue('Name', input.Name);
gr.setValue('Serial number', input.serial_number);
gr.setValue('Model number', input.model_number);
gr.setValue('MAC Address', input.mac_address);
gr.setValue('PO number', input.po_number);
// gr.setValue('Support group', 'Desktop Services');
// gr.setValue('Hardware Status', 'In Stock');
if(!gs.nil( input.cmdb_ci))
gr.setValue('cmdb_ci_computer', input.cmdb_ci_computer);
gr.insert();
})(input);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 02:30 AM
Hi Mark,
It will be helpful to resolve your issue if you can elaborate about the problem you are facing while implementing this. Like any error you are able to see? or something not responding etc.
Thanks
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 07:22 AM
Hello Aniket,
This is the Action Item on the Mobile Agent,
I am trying to do a call to Script Include to check for duplication, but the App is not allowing it.
(function WriteBackAction(input) {
//Check to find if Serial Number or Name is a Duplication
var aSerial = new x_sfhs_sfh_compute.validateSerialorNameMobileApp.doesCompSerialExist(input.serial_number);
var aName = new x_sfhs_sfh_compute.validateSerialorNameMobileApp.doesCompNameExist(input.name);
if(aSerial == true && aName == true){
// Create New Computer Record if not a Duplication
var gr = new GlideRecord('cmdb_ci_computer');
gr.initialize();
gr.setValue('name', input.name);
gr.setValue('serial_number', input.serial_number);
gr.setValue('model_number', input.model_number);
gr.setValue('mac_address', input.mac_address);
gr.setValue('po_number', input.po_number);
gr.setValue('support_group', '6b5b409e4fa6de00bf23f7e18110c760');
gr.setValue('hardware_status', 'in_stock');
gr.insert();
}else
{
if(aSerial == false)
gs.error('serial number found - please double');
if(aName == false)
gs.error('name found - please double');
}
})(input);
the Script Include
var validateSerialorNameMobileApp = Class.create();
validateSerialorNameMobileApp.prototype = {
initialize: function() {
},
doesCompNameExist: function(name) {
var grName = new GlideRecord('cmdb_ci_computer');
grName.addQuery('name', name);
grName.query();
if (gr.next())
return false;
else
return true;
},
doesCompSerialExist: function(serial_number) {
var grSerial = new GlideRecord('cmdb_ci_computer');
grSerial.addQuery('serial_number', serial_number);
grSerial.query();
if (gr.next())
return false;
else
return true;
},
type: 'validateSerialorNameMobileApp'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 08:05 AM
Hi Mark,
If I am understanding it correct in the line
x_sfhs_sfh_compute.validateSerialorNameMobileApp.doesCompSerialExist(input.serial_number);
x_sfhs_sfh_compute is the scope , and validateSerialorNameMobileApp is the your scriptInclude, if that's so , try usingx_sfhs_sfh_compute.validateSerialorNameMobileApp().doesCompSerialExist(input.serial_number);
I think () is missing, once test this, hope it should work.
Feel free to reply if still it troubles you.
Please mark the answer as correct/helpful if this helps.
Thanks
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 11:15 AM
Thanks for the Help, something is still off somewhere
Action Item
var aSerial = new global.validateSerialorNameMobileApp().doesCompSerialExist(input.serial_number);
if (aSerial == false) {
gs.error('serial number found - please double');
gs.addErrorMessage(gs.getMessage("Found Serial Number already in Use"));
return;
}
Script Include
doesCompSerialExist: function(serial_number) {
var grSerial = new GlideRecord('cmdb_ci_computer');
grSerial.addQuery('serial_number', serial_number);
grSerial.query();
if (gr.next())
return false;
else
return true;
},
