- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 05:17 AM
How to assign assets in Servicenow HAM to "Last logged on User" if "Primary User" is same as?
How to set Assigned to in 'alm_hardware' Table in Servicenow HAM to "Last logged on User" of cmdb_ci_computer table if "Primary User" is same as "Last logged on User" of 'cmdb_ci_computer' Table?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 08:47 PM
Issue Resolved.
Please find below Code:-
Script Include:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 11:24 AM
Hi @VIKAS45 ,
I think you should create a BR -
(function executeRule(current, previous) {
// Get the 'cmdb_ci_computer' record for the hardware asset
var computerRecord = current.cmdb_ci_computer.getRefRecord();
if (computerRecord) {
var primaryUser = computerRecord.primary_user.toString();
var lastLoggedOnUser = computerRecord.last_logged_on.toString();
// Check if 'Primary User' is the same as 'Last logged on User'
if (primaryUser === lastLoggedOnUser) {
// Set the 'Assigned to' field in the 'alm_hardware' table to 'Last logged on User'
current.assigned_to = computerRecord.last_logged_on;
}
}
})(current, previous);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 02:48 AM
Hi Tushar it is not working.
please let me know
How to set Assigned to in 'alm_hardware' Table in Servicenow HAM to "Last logged on User" of cmdb_ci_computer table if "Primary User" is same as "Last logged on User" of 'cmdb_ci_computer' Table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 10:43 PM
I already informed it depends on your use-case
1)In Client Script - if you want to see the real-time change on UI
2)In Fix Script - this is like a 1 time activity and you want to update all the records
3)Background script - not preferred
4)Business Rule - when you want to see the change once record is saved
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader