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:08 PM
Evaluator: com.glide.script.RhinoEcmaError: invalid return
script : Line(5) column(7)
return;
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;
}
Evaluator: com.glide.script.RhinoEcmaError: syntax error
script : Line(9) column(2)
},
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;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019 12:34 AM
Hi Mark,
In the script above,
var grSerial = new GlideRecord('cmdb_ci_computer');
grSerial.addQuery('serial_number', serial_number);
grSerial.query();
if (gr.next())
return false;
else
return true;
It should be grSerial.next() and not the gr.next(). I think it's the typo, once change and run, hopefully it should work.
Thanks
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2019 09:21 AM
Aniket,
Do you have any more ideas? Still having issues with errors.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2019 10:09 PM
if (aSerial == false)
I can suspect above line as error prone, please check the type of aSerial before comparing it with 'false' , though you are using == not === , but still I would recommend you to try this and share the outcome (also the log message):
var aSerial = new global.validateSerialorNameMobileApp().doesCompSerialExist(input.serial_number);
gs.info("type : " + typeof aSerial + "and value is " + aSerial) ;
/** if (aSerial == false) {
gs.error('serial number found - please double');
gs.addErrorMessage(gs.getMessage("Found Serial Number already in Use"));
} */
return;
second thing is , you can try this (keeping return out of if block)
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;
Thanks
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 01:41 PM
Is it possible to do the same thing on the Function Action on the Condition Tab?
I have found different usage for this:
1.var gr = new GlideRecord('sc_request'); if (gr.get(current. sysapproval)) answer = gr.canRead(); else answer = false;
2. new global.FSMMobileUtil().hasQuestionnaireForthisRecord(current.sys_id);
3. current.state=='3' || current.state=='4'
So why can't I figure this out 😞 I want to check if Name or Serial Number is already in the cmdb_ci_computer then either create record or send failed message.
