Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

calling scriptinclude from link in catalog

t-takumi
Tera Contributor

I want to place a link in a catalog item (created via Record Producer) that calls a Script Include. Is it possible to generate a link using a Script Include? Also, is there a way to call a script that performs server-side processing without calling a Script Include?

3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @t-takumi 

 

Try this:

 

  1. Create a variable
  • Open your Record Producer.
  • Create a new Variable.
  • Set the Type to Rich Text Label or Custom (using a UI Macro/Widget).
  • Give it a name (e.g., dynamic_link_placeholder)

 

  1. Create the Client-Callable Script Include
  • Navigate to System Definition > Script Includes >Click New.
  • Client callable : checked

var DynamicLinkGenerator = Class.create();

DynamicLinkGenerator.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

    generateCatalogLink: function() {

        var recordSysId = this.getParameter('sysparm_record_id');

         var baseUrl = "/sp?id=sc_cat_item&sys_id="; // Example portal route

        var finalUrl = baseUrl + recordSysId;

        return '<a href="' + finalUrl + '" target="_blank" style="color: blue; text-decoration: underline;">Click Here to View Details</a>';

    },

    type: 'DynamicLinkGenerator'

});

 

  1. Create the Catalog Client Script
  • On your Record Producer, go to the Catalog Client Scripts related list.> Click New.
  • Set the Type to onLoad (or onChange depending on your requirements).
  • Set the UI Type to All

function onLoad() {

    var ga = new GlideAjax('DynamicLinkGenerator');

    ga.addParam('sysparm_name', 'generateCatalogLink');

    ga.addParam('sysparm_record_id', g_form.getUniqueValue());

    ga.getXMLAnswer(function(response) {

        if (response) {

              g_form.setValue('dynamic_link_placeholder', response);

        }

    });

}

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@t-takumi 

you can show link in catalog form using different variable types (Custom or HTML)

But what should happen on click of that?

what's your exact business requirement?

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

I want to run a query on a table with a server script when a link is clicked.
After that, I want to export the file.