Automatically open the attached Catalog Item from an AC Task in the ESC portal and close the AC task

umeshmeesala
Tera Contributor

I have created custom tables (AC Case and AC Task) and added a Catalog Item reference field on the AC Task table. When an AC Task is assigned to a user and the user opens it in the ESC portal, how can I make the attached Catalog Item open automatically, and upon submitting the request, how can the corresponding AC Task be automatically closed as Complete?

4 REPLIES 4

Manthira Moorth
Tera Expert
To automatically open a Catalog Item from an AC Task in the Employee Center (ESC) portal and close the task upon submission, follow these steps:
 
1. Automatically Open Catalog Item 
You can use a Catalog Client Script on the AC Task table (or a specific widget) to redirect the user as soon as they open the task record in the portal. 
  • Create an onLoad Client Script for your custom AC Task table.
  • Set the UI Type to All or Mobile/Service Portal.
  • Script Logic:
    javascript
    function onLoad() {
        var catItemID = g_form.getValue('u_catalog_item'); // Replace with your reference field name
        if (catItemID) {
            // Redirect to the catalog item page in the ESC portal
            // Passing the current task ID in the URL to track it later        top.window.location = "/esc?id=sc_cat_item&sys_id=" + catItemID + "&sysparm_parent_task=" + g_form.getUniqueValue();
        }
    }
    Use code with caution.
  • Note: Ensure Isolate script is set to false to allow access to top.window. 
 
2. Close AC Task Upon Submission 
Since submitting a Catalog Item creates a Requested Item (RITM), you need a mechanism to link that submission back to the originating AC Task and close it. 
  • Step A: Capture the Parent Task
    Create a hidden variable on your Catalog Item (e.g., parent_task_id) to store the task sys_id from the URL. Use an onLoad Catalog Client Script to populate it:
    javascript
    function onLoad() {
        var urlParams = new URLSearchParams(window.location.search);
        var parentTask = urlParams.get('sysparm_parent_task');
        if (parentTask) {
            g_form.setValue('parent_task_id', parentTask);
        }
    }
    Use code with caution.
  • Step B: Update the AC Task via Business Rule
    Create an after Insert Business Rule on the sc_req_item (Requested Item) table:
    • Condition: Only run if the originating Catalog Item matches yours and the parent_task_id variable is not empty.
    • Script Logic:
      javascript
      (function executeRule(current, previous /*null when async*/) {
          var parentTaskID = current.variables.parent_task_id;
          if (parentTaskID) {
              var grTask = new GlideRecord('u_ac_task'); // Your custom AC Task table
              if (grTask.get(parentTaskID)) {
                  grTask.state = 3; // 3 is usually 'Closed Complete'            grTask.work_notes = "Automatically closed after submission of " + current.number;
                  grTask.update();
              }
          }
      })(current, previous);
      Use code with caution.
 
Summary of Workflow
  1. User opens AC Task in ESC.
  2. Client Script detects the task and immediately redirects the user to the Catalog Item, passing the Task ID as a URL parameter.

@Manthira Moorth 

Would you mind sharing screenshots to support your solution so it can benefit the community?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron

@umeshmeesala 

can you share screenshots on how user is navigating in ESC and opening that catalog task?

is that user using My Tasks in header?

If yes and if it's opening SC Task then that's OOTB behavior as that's the record which has task assigned to logged in user.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

we have the existing functionality in HRSD where we have the Task Type as "Submit a Catalog Item". which will assign the Task to the Person and the person will fill out the Form, once the form is filled the case created and the task will get closed.

 

Attaching the screenshot for your reference in the image"screen11.png"

 

we are trying to get the functionality on the custom table "AC Task".

 

We are able to get the task into the ESC, but we are not getting the form details and Activity Stream.

 

Attaching the screenshot for reference "ac task.png".