ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 05:58 AM - edited 11-28-2024 09:27 PM
i am trying to set values in below fields but not able to set for some fields in imac form :
To/New Office Location
Date Received
IMAC Items> Model/Part Number
Add a link to the IMAC to the SCTask work notes
Description
Create UI action to create an IMAC as part of Hardware Return Requested Item. This button should be available on SC Tasks
Name: Create IMAC
Show as button/link on form
Actions:
Create IMAC
Submitter: User clicking the UI action
Asset Type: IT Equipment
Request Type: Move
Short Description: IT Equipment Move by “User Clicking the UI Action”
Assigned Group: Accounting group
Assigned to:
State: Submitted
Stage: submitted
Details
Description: Itemized List - Configuration Item…Model ID
Date Received: Date of Submission
From/Current Details
From/Current Company - Requested Item…Requested For…Company
From Current Employee or Custodian - Requested Item…Requested For
From/Current Office Location - Requested Item…Requested For…Location
From/Current Location Details - None
To/New Details
To/New Company - Technology
To/New Employee or Custodian - blank
To/New Office Location - Herndon, VA
To/New Location Details - AD
IMAC Items
Serial / Asset Tag / Description / Model/Part Number / Configuration Item / Manufacturer company - All from Itemized list configuration Item info
Add a link to the IMAC to the SCTask work notes
code:
// Step 1: Get the current SC_Task and parent RITM
var taskGr = current; // Current SCTask
var ritmGr = taskGr.request_item; // Associated RITM
var itemizedList = ritmGr.variables.itemized_list; // Itemized list from RITM variables
// Parse the itemized list
var items = JSON.parse(itemizedList); // Ensure it's a valid JSON array
// Step 2: Create the IMAC record first
var imacGr = new GlideRecord('u_imac'); // Custom IMAC table
imacGr.initialize();
// Populate basic IMAC fields
imacGr.u_asset_type = 'IT Equipment';
imacGr.u_request_type = 'Move';
imacGr.short_description = 'IT Equipment Move by ' + gs.getUser().getDisplayName();
imacGr.assignment_group = 'Accounting IMAC group';
imacGr.state = -1;
imacGr.u_stage = 'submitted';
// Populate "From/Current" fields
imacGr.u_from_company = ritmGr.requested_for.company.getDisplayValue() || '-- None --';
imacGr.u_from_employee_or_custodian = ritmGr.requested_for.getDisplayValue() || '-- None --';
imacGr.u_from_office_location = ritmGr.requested_for.location.getDisplayValue() || '-- None --';
imacGr.u_from_location_details = 'None';
// Populate "To/New" fields
imacGr.u_to_company = 'Technology';
imacGr.u_to_employee_or_custodian = '';
imacGr.u_to_office_location = 'Herndon, VA';
imacGr.u_to_location_details = 'PEU';
// Insert the IMAC record
var imacSysId = imacGr.insert(); // Capture the sys_id of the inserted record
// Step 3: Loop through the itemized list and create associated IMAC Assets
var description = 'Itemized List - Configuration Item:\n';
for (var i = 0; i < items.length; i++) {
var item = items[i];
var configurationItem = item.configuration_item; // Configuration Item sys_id
// Query the cmdb_ci table to check if it's of class "cmdb_ci_computer"
var ciGr = new GlideRecord('cmdb_ci');
if (ciGr.get(configurationItem)) {
if (ciGr.sys_class_name == 'cmdb_ci_computer') {
// Build the description
description += 'Configuration Item: ' + ciGr.name + '\n';
description += 'Model ID: ' + (ciGr.model_id ? ciGr.model_id.getDisplayValue() : 'Not Available') + '\n';
// Create a new record in u_imac_assets
var assetGr = new GlideRecord('u_imac_assets');
assetGr.initialize();
// Populate fields for IMAC Asset
assetGr.u_imac = imacSysId;
assetGr.u_serial_number = item.serial_number || 'Not Available';
assetGr.u_asset_tag = item.eplus_asset_tag || 'Not Available';
assetGr.u_description = item.item_description || 'Not Available';
assetGr.u_model = ciGr.model_id ? ciGr.model_id.toString() : 'Not Available';
assetGr.u_configuration_item = ciGr.sys_id;
assetGr.u_manufacturer_company = ciGr.manufacturer.getDisplayValue() || '-- None --';
// Insert the IMAC Asset record
assetGr.insert();
}
}
}
// Step 4: Update the IMAC record with the description
imacGr.description = description;
imacGr.update();
// Step 5: Add a work note in the SCTask referencing the IMAC record
taskGr.work_notes = 'IMAC created for Hardware Return. <a href="' + imacGr.getLink() + '" target="_blank">Click here to view the IMAC record</a>';
taskGr.update();
// Step 6: Redirect back to the SCTask record
action.setRedirectURL(current);