Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Creating INC ticket by using the scheduled job

RC10
Tera Contributor

Hi All,

We have implemented the logic to create an INC ticket based on the scheduled job execution. However, for the INC ticket Description field, we need to populate a catalog URL in a user-friendly format.

Currently, the complete catalog URL is displayed in the Description. Instead, we would like to display a clickable text such as “Service Account Password Reset”. When the user clicks on this text, it should open the corresponding catalog item in a new browser window/tab.

Advance thanks...



function createExpiryIncident(svcAcct) {

    gs.info("Entered createExpiryIncident for: " + svcAcct.name);
    var instanceUrl = gs.getProperty('glide.servlet.uri');
    var resetCatalogItem = '6a067b4fdbfba01456456a9ed39619ed';

    var inc = new GlideRecord('incident');
    inc.initialize();
    inc.caller_id = "6816f79cc0a8016401c5a33be04be441";
 var supportGroup = svcAcct.support_group.getRefRecord();

    gs.info("Support Group: " + supportGroup.name);
     inc.assignment_group = svcAcct.support_group;
    inc.cmdb_ci = svcAcct.getUniqueValue();

    inc.short_description =  "ACTION REQUIRED: Service Account Password Expiring - " + svcAcct.name;


   inc.description = "The password for Service Account " + svcAcct.name + " is set to expire on " + svcAcct.u_password_exception_granted.getDisplayValue() + ".\n\n" + "Please submit a Service Account Password Reset:\n" + instanceUrl + "sp?id=sc_cat_item&sys_id=" + resetCatalogItem + "\n\n" + "If you are no longer using this account please disable your account here." + "\n\n" + "If you believe you received this service account password expiration in error please click here.";

    var incidentSysId = inc.insert();

    gs.info("Incident Sys Id = " + incidentSysId);

    if (!incidentSysId) {
        gs.error("Incident creation failed");
        gs.error("Last Error: " + inc.getLastErrorMessage());
    }

    return incidentSysId;
}
1 REPLY 1

Tejas Adhalrao
Mega Sage

hi @RC10 ,

 

Yes, this can be done. Since Incident Description supports HTML, instead of putting the full URL directly, create an anchor tag with the text you want to display.

 

For example, you can change your Description assignment to:

 

inc.description = "The password for Service Account " + svcAcct.name +
" is set to expire on " + svcAcct.u_password_exception_granted.getDisplayValue() +
".<br><br>" +
"Please submit a <a href='" + instanceUrl + "sp?id=sc_cat_item&sys_id=" + resetCatalogItem + "' target='_blank'>Service Account Password Reset</a>.<br><br>" +
"If you are no longer using this account please disable your account here.<br><br>" +
"If you believe you received this service account password expiration in error please click here.";

 

This will display "Service Account Password Reset" as clickable text instead of showing the complete URL.

The target="_blank" will open the catalog item in a new browser tab/window.

One thing to verify is whether the Description field is rendering HTML in the UI where the incident is being viewed. If the HTML is displayed as plain text, then we need to check the specific Incident form/workspace configuration.

 

If this helps, please mark it as Helpful and accept the solution.
Regards,
Tejas