- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 06:05 AM - edited 08-21-2024 06:06 AM
Hi,
i have a catalog item to reassign assets which has the following variables:
current_user_this_asset_is_assigned_to , which_asset_needs_to_be_reassigned , new_user_this_asset_need_to_be_assigned_to .
i need to create a run script in the workflow which reassigns the asset in (which_asset_needs_to_be_reassigned) to the user that is selected in (new_user_this_asset_need_to_be_assigned_to) on the cmdb_ci_computer table.
i also need to make sure the asset is reassigned on the date that is selected in the variable when_does_this_change_need_to_be_performed (date picker)
i tried afew things but couldnt make it work, this is my script i started with:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 06:55 AM
It looks like you're on the right track with your script, but there are a few adjustments needed to correctly reassign the asset and ensure it’s updated with the correct date. Here’s a revised version of your script:
Key Points:
Query the Asset Correctly: Ensure you use the correct field name and variable for querying the asset. In the addQuery method, sys_id should match the asset you want to reassign.
Update the Correct Fields: The field you’re updating is assigned_to, which should be the reference to the new user. Ensure that assigned_to is the correct field in your cmdb_ci_computer table.
Handle the Date Field: Ensure that the field where the date needs to be set (assignment_date in this case) is correct and exists in your table. Also, the GlideDateTime object is used to properly format the date.
Variable Names: Make sure the variable names in current.variables match exactly with the names used in your catalog item.
You may need to adapt the script slightly depending on the exact field names and requirements of your instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 07:32 AM
The next step is to add some logging, something like this:
workflow.info('Run Script starting');
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('sysid',current.variables.which_asset_needs_to_be_reassigned);
gr.query();
if (gr.next()) {
workflow.info('Record found ' + gr.name + ' Currently assigned to ' + gr.assigned_to + ' To be assigned to ' + current.variables.new_user_this_asset_need_to_be_assigned_to);
gr.assigned_to = current.variables.new_user_this_asset_need_to_be_assigned_to;
workflow.info('New Assigned to = ' + gr.assigned_to;
gr.update();
} else {
workflow.info('Computer record not found');
You can view these on the Log tab when viewing the Context from the Related Link on the RITM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 06:55 AM
It looks like you're on the right track with your script, but there are a few adjustments needed to correctly reassign the asset and ensure it’s updated with the correct date. Here’s a revised version of your script:
Key Points:
Query the Asset Correctly: Ensure you use the correct field name and variable for querying the asset. In the addQuery method, sys_id should match the asset you want to reassign.
Update the Correct Fields: The field you’re updating is assigned_to, which should be the reference to the new user. Ensure that assigned_to is the correct field in your cmdb_ci_computer table.
Handle the Date Field: Ensure that the field where the date needs to be set (assignment_date in this case) is correct and exists in your table. Also, the GlideDateTime object is used to properly format the date.
Variable Names: Make sure the variable names in current.variables match exactly with the names used in your catalog item.
You may need to adapt the script slightly depending on the exact field names and requirements of your instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:24 AM
@waqask this works but i used a seperate timer for the date check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:17 AM
I'm struggling to see how this AI copy and paste provides any value or insight over the troubleshooting process I was walking you through in my three responses. It's not even any different than the original script I provided earlier!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:47 AM
@Brad Bowman i added the info to my script yesterday and saw that it was pulling in from the wrong table i think so your response definetly helped!
im not saying i copied and pasted the script but it got it to work thats the most important