- 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-18-2023 06:22 AM - edited 07-27-2023 11:25 AM
Hi Vikas,
something like this can be useful?
(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);
Mark as correct and helpful if it solved your query.
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 10:07 PM - edited 07-19-2023 10:54 AM
Hi Tushar,
We have to check condition in cmdb_ci_computer as you mentioned and set value in alm_hardware table.
Please confirm where should I write this code.
1)In Client Script
2)In Fix Script
3)Background script
4)Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:55 AM
Hi Tushar it is not working.
please let me know to use the below script in Client Script instead of Business Rules.
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
09-21-2023 08:47 PM
Issue Resolved.
Please find below Code:-
Script Include:-