Updating Multiple Assets on Agent Mobile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2022 12:48 PM
I've been trying to figure this out off and on for a long time, but is there a way to update the same field on multiple assets in one go on the agent mobile app?
This is close, but... not quite:
https://community.servicenow.com/community?id=community_question&sys_id=eae673bbdbfe8810d82ffb24399619e6
https://www.youtube.com/watch?v=mHrsJQ2ENXU
https://developer.servicenow.com/connect.do#!/share/contents/9695572_multiple_asset_scanning_using_service_now_mobile_apps?t=PRODUCT_DETAILS
It's great work by
I have multi scan working just fine in agent mobile (not quite as pretty as Aluru's work), and it brings up the multiple scanned assets for me to update by choosing an asset and updating the field I want to, but...
I have requirements to allow the update button to work across the assets in one update. Is this possible? You scan 10 assets that are in stock and you can open the update form and assign to all 10 in one go.
I think what concerns me is the documentation says "Your button is configured for multi-scan, and your users can begin creating records." I don't want to create multiple but update multiple. Please oh please don't be an enhancement request.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 04:25 PM
Did you figure it out? I am trying to achieve exactly same thing. Any pointer will be really helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:22 AM
Hi, @Sneha32:
Yes, I did figure it out. Overall, it's kind of disappointing that really the only scripting call is during the update of records. It relies an awful lot of the press of the button in the app to do ALL the lifting and so I tried to account for as many different scenarios as possible all in the action item button.
But... here's what I did. Let me know if you have any questions; I'll try to answer but it's been a minute so I'm a little hazy on how the heck I built this out.
Asset Management Mobile scope in the studio
Custom Action Item: Update Multiple Assets
Data Parameters: I included in attached screenshots
Note: some of these fields are custom and very specific to our business so you probably don't want/need those.
Script:
function WriteBackAction(input, actionResult) {
var theAsset, userCompany, theAssignTo, userRoomNumber, userDepartment, statusTest, currentAssign, currentRoomNumber, currentCompany, currentDepartment, userAssigned, currentInstall, currentSub, inputCompany, inputState, inputSub, inputVerified, inputComments, inputStockRoom, inputRoomNumber, currentComments, currentStockRoom, inputAssignedTo, stateCheck, theAssetTag, roomNumberResetter, installResetter;
//Uncomment out to test update form and stay on screen.
//var inputString = JSON.stringify(input);
//gs.addErrorMessage(inputString /* + " test? " + input.grouped_assets[0]["Asset Tag"]*/ );
for (var i = 0; i < input.grouped_assets.length; i++) {
theAssetTag = input.grouped_assets[i]["Asset Tag"];
//Set the status/state checker:
statusTest = '0';
stateCheck = '0';
//Get some input fields:
inputState = input.state;
inputSub = input.substate;
inputVerified = input.u_verified;
inputStockRoom = input.stockroom;
inputComments = input.comments;
inputRoomNumber = input.u_room_number;
inputAssignedTo = input.assigned_to;
inputCompany = input.company;
//Get the Asset:
theAsset = new GlideRecord('alm_asset');
theAsset.get('asset_tag', theAssetTag);
//Get some values from the Asset:
currentAssign = theAsset.assigned_to;
currentCompany = theAsset.company;
currentDepartment = theAsset.department;
currentRoomNumber = theAsset.u_room_number;
roomNumberResetter = currentRoomNumber.toString();
currentSub = theAsset.substatus;
currentInstall = theAsset.install_status;
installResetter = currentInstall.toString();
currentStockRoom = theAsset.stockroom;
currentComments = theAsset.comments;
if (currentInstall != '6' && inputState) {
statusTest = '1';
}
//Get the user record if inputted:
if (inputAssignedTo) {
theAssignTo = new GlideRecord('sys_user');
theAssignTo.get(input.assigned_to);
//Get some vaues from the User:
userAssigned = inputAssignedTo;
userCompany = theAssignTo.company;
userDepartment = theAssignTo.department;
userRoomNumber = theAssignTo.u_room_number;
}
//Assigning an unassigned in stock asset with no company:
if (inputAssignedTo && !currentAssign && currentInstall == '6' && !currentCompany) {
theAsset.assigned_to = inputAssignedTo;
theAsset.department = userDepartment;
theAsset.install_status = '1';
theAsset.substatus = '';
stateCheck = '1';
//If Company manually overridden:
if (inputCompany != '') {
theAsset.company = inputCompany;
} else {
theAsset.company = userCompany;
}
}
//Reassigning an assigned asset:
if ((inputAssignedTo && currentAssign && inputAssignedTo != currentAssign) || (inputAssignedTo && !currentAssign && currentCompany)) {
if (userCompany != currentCompany) {
gs.addErrorMessage("Cannot assign to an associate that is not in " + theAsset.company.name + ". " + theAssignTo.name + " is in " + theAssignTo.company.name);
} else {
theAsset.assigned_to = inputAssignedTo;
theAsset.department = userDepartment;
theAsset.install_status = '1';
theAsset.substatus = '';
stateCheck = '1';
}
}
//If moving asset to In Stock
if ((inputState == '6' || inputStockRoom || (!inputAssignedTo /*-->*/ && !inputRoomNumber /*to account for hotel space reassignment*/ )) && statusTest == '1') {
if (!input.stockroom) {
gs.addErrorMessage('Please add a stockroom and resubmit');
} else {
theAsset.assigned_to = '';
theAsset.install_status = '6';
theAsset.stockroom = inputStockRoom;
theAsset.u_room_number = '';
theAsset.substatus = 'available';
theAsset.department = '';
stateCheck = '1';
}
}
//Check if Room Number manually overriden or set from user record:
if (inputRoomNumber != '' || inputRoomNumber != currentRoomNumber) {
theAsset.u_room_number = inputRoomNumber;
} else if (theAsset.u_room_number != userRoomNumber) {
theAsset.u_room_number = userRoomNumber;
}
//Check if state is manually overriden:
if (stateCheck != '1') {
theAsset.install_status = inputState;
if (inputSub) {
theAsset.substatus = inputSub;
} else {
theAsset.substatus = '';
}
}
//Verify asset:
if (inputVerified) {
theAsset.u_verified = inputVerified;
}
//Add comments:
if (inputComments && inputComments != currentComments) {
theAsset.comments = inputComments;
}
//Blank field check... Can't leave these empty. Use existing values to rewrite:
if (inputState == '' && theAsset.install_status != '1') {
theAsset.install_status = installResetter;
//gs.addErrorMessage("state? " + inputState + " state " + installResetter);
}
if (inputRoomNumber == '') {
theAsset.u_room_number = roomNumberResetter;
//gs.addErrorMessage("room? " + inputRoomNumber + " room " + roomNumberResetter);
}
theAsset.update();
}
})(input, actionResult);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:41 PM
@ctsmith Thanks so much. It solved my problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi guys,
I know that it is a long time and a lot have changed. But is there a way you can help me out on this topic?
I don't have experience with Mobile app, and it seems the learning courses have vanished from University now. I have managed to have the folowing:
- The list screen page
- The input form screen page that is taking the scanned variables
- The data item where I have the script
Now from the script I am simply logging the input object, and no matter what I do, I am not able to get the assets that I scanned in the previous screen.
So the flow that I am trying to build, following the same patters as I saw ServiceNow did, is to click on Scan Assets button, I scan the assets, I get the list of assets found, then I click on a button from the list screen, I get to the screen where I update the fields (like status and substatus) and I submit the change.
Let me know if that is clear and you can recall how you guys did it 😄
Thanks