UI Action to specific General IT request copy description,short description and caller to variables

Ryan O_
Tera Contributor

I have a request for a ui action from incident form same conditions as Create Request that is ootb. However they specifically want it to point to one catalog item and that that catalog item generate the description, short description and caller fields from incident to the General IT catalog variable Requestor = caller_id, variable short_description = short_description and variable description = description.

 

i have reviewed some documentation on it but still confused as to why its not working. my script is below. 

 

 

// Directly set the necessary fields on the current incident record
current.state = '7';  // 7 is task closing numerical state for closed.
current.close_notes = "Closed Incident, General IT request created"; // can be updated to additional notes to user as well or adding new line.  
current.close_code = 'Transferred to Request';  // created this in dev, can update if something else is needed.

// Update Incident
current.update();

//  URL for the General IT request form
url += '&sysparm_query=';
url += 'short_description=' + encodeURIComponent(current.short_description);
url += '^description=' + encodeURIComponent(current.description);
url += '^requestor=' + encodeURIComponent(current.caller_id);

// Use action.setRedirectURL to redirect to the constructed URL
action.setRedirectURL(url);
2 REPLIES 2

Deepak Shaerma
Kilo Sage

Hi @Ryan O_ 

 

Step 1: Creating the UI Action

 

1. Navigate to System Definition > UI Actions.

2. Create New UI Action with the following attributes:

- Name: Populate and Open Catalog Item (or any meaningful name)

- Table: Incident

- Action Name: A unique identifier for the action, like open_catalog_item

- Form Button: Checked (to make it appear as a button on the form)

- Client: Checked, because you’ll be using a client-side script to redirect the user’s browser

- Condition: Copy the conditions from the OOTB “Create Request” UI action if you want to mirror its availability

3. Script:

 

Here’s an script.

Note: Replace YOUR_CATALOG_ITEM_SYS_ID, requestor, short_description, and description with the actual Sys ID and variable 

 

var catalogItemId = ‘YOUR_CATALOG_ITEM_SYS_ID’;
var currentCallerId = g_form.getValue(‘caller_id’);
var currentShortDescription = g_form.getValue(‘short_description’);
var currentDescription = g_form.getValue(‘description’);

// Encode the variables’ values to be URL-safe
var requestorVar = encodeURIComponent(currentCallerId);
var shortDescriptionVar = encodeURIComponent(currentShortDescription);
var descriptionVar = encodeURIComponent(currentDescription);

// Construct the redirect URL
var url = ‘/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=’ + catalogItemId;
url += ‘&sysparm_variable_requestor=’ + requestorVar;
url += ‘&sysparm_variable_short_description=’ + shortDescriptionVar;
url += ‘&sysparm_variable_description=’ + descriptionVar;

// Redirect the user to the Catalog Item form with prepopulated fields
g_navigation.open(url, ‘_blank’);

 

PLEASE MARK THIS AS HELPFUL AND ACCEPTED SOLUTION IF THIS HELPS YOU. THIS WILL HELP BOTH ME AND THE COMMUNITY 

 

THANKS AND REGARDS 

 

DEEPAK SHARMA

Ryan O_
Tera Contributor

updated and tested, it seems the client field when 'checked' goes to this search page after making those updates. with Null displaying as the value attached screenshot.

 

besides where you explicitly have catalogItemID or sys id labeled where else do i need to add the sys id you list description,short_description and requestor are correct for the variables.

 

form button did not do anything for some reason but not a big issue as this would still be the right click 'form context menu' selection.