The CreatorCon Call for Content is officially open! Get started here.

I want action button functionality for RITM same as incident on ESC Portal.

mania
Tera Contributor

Hi,

There is OOB functionality for Incident Action button for Portal, I want same functionality to be worked for Requested Item i have clone the same widget and changed table name i got the button but functionality is still not same as incident. Can anyone help me with updated server script code.

(function() {
    var incidentGr = new GlideRecord('sc_req_item');
  var incidentSysId = options.sys_id;
if (!incidentSysId && $sp.getParameter('table') == 'sc_req_item')
    incidentSysId = $sp.getParameter('sys_id');
  //gs.addInfoMessage('sys_id'+incidentSysId);
if (!incidentSysId && $sp.getParameter('table') == 'universal_request') {
    var urGr = new GlideRecord('universal_request');
    urGr.get($sp.getParameter('sys_id'));
    incidentSysId = urGr.primary_task + "";
  }
/* Actions - Start */
    if (input && input.action == 'resolveIncident' && incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "write")) {
        //incidentGr.incident_state = global.IncidentState.RESOLVED;
    incidentGr.state = 3;
    incidentGr.resolved_by = gs.getUserID();
    data.isIncidentResolved = incidentGr.update();
    }
if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "write")) {
        incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
    incidentGr.state = global.IncidentState.IN_PROGRESS;
    data.isIncidentReopened = incidentGr.update();
    gs.addInfoMessage(gs.getMessage("Request reopened"));
    }
if (input && input.action == 'closeIncident' && incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "write")) {
    incidentGr.incident_state = global.IncidentState.CLOSED;
    incidentGr.state = global.IncidentState.CLOSED;
    data.isIncidentClosed = incidentGr.update();
    }

/* Actions - End */
/* Load incident data */
   if (incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "read")) {
    var incidentUtils = new global.IncidentUtils();
    data.canResolve = incidentUtils.canResolveIncident(incidentGr);
    data.canReopen = incidentUtils.canReopenIncident(incidentGr);
    data.canClose = incidentUtils.canCloseIncident(incidentGr);
    data.showActions = data.canResolve || data.canReopen || data.canClose;
    }

 function hasPermissions(gr, operation) {
        if (operation == "read" && gr.canRead())
            return true;

  if (operation == "write" && gr.canWrite())
            return true;

 return (gr.getValue("caller_id") == gs.getUserID()) || (gr.getValue("opened_by") == gs.getUserID());
    }

    data.i18n = {};

})();

mania_2-1705501230724.png

mania_3-1705501506771.png

Thanks in Advance!

2 REPLIES 2

Ahana 01
Tera Expert


Sure, you can achieve this by creating a UI Action in ServiceNow. Here are the steps:

1. Navigate to System UI > UI Actions in ServiceNow.
2. Click on New to create a new UI Action.
3. Fill in the necessary fields:
- Name: Give a name to your UI Action.
- Table: Select the table for which you want to create the UI Action. In your case, it would be "Requested Item [sc_req_item]".
- Action name: This is automatically populated based on the name you provide.
- Client: Check this box to make the UI Action run on the client-side.
- List Choice: Check this box to make the UI Action appear in the choice list.
- Form Button: Check this box to make the UI Action appear as a button on the form.
- Script: Write the script that you want to execute when the UI Action is clicked.
4. Click on Submit to save the UI Action.

Here is a sample script for a UI Action:

javascript
function onClick() {
var ritm = new GlideRecord('sc_req_item');
ritm.get(g_form.getUniqueValue());
// Perform your action here
ritm.update();
action.setRedirectURL(current);
}


Please replace "// Perform your action here" with the actual action you want to perform on the RITM record.

Remember, this is a basic example. Depending on your requirements, you might need to modify the script. Also, make sure to test the UI Action in a non-production instance before deploying it to production.


nowKB.com

For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home
Kindly mark correct and helpful if applicable

hnnj
Tera Contributor

Hi i have same requrment i can wirte code logic can you tell me from where to add cloned widget with action button