Based on reference type of variable selection we need to display the link in below

mani55
Tera Contributor

we have software name variable is there and it's a lookup select box variable so based software name selection that software name related link we need to display like  below 

 

mani55_0-1779782210171.png

 

 

example :

 

software name: Auto Viewer & Editor
Link: companyportal:ApplicationId=720fb74b-3e24

This product is already available in Company Portal.

Click here to access it and install the product by yourself!
If you require installation support or need to install a specific version not available in the Company Portal, please select YES in the installation assistance question and specify the required version in the Description field.

software name:  Task & Reminders
Link: companyportal:ApplicationId=fd83f41e-1b5039a9bcac

This product is already available in Company Portal.

Click here to access it and install the product by yourself!
If you require installation support or need to install a specific version not available in the Company Portal, please select YES in the installation assistance question and specify the required version in the Description field.

 

how we can archive this scenario through widget

8 REPLIES 8

Hi @mani55 

Create a script include: SoftwarePortalAjax
 
var SoftwarePortalAjax = Class.create();
SoftwarePortalAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
    getPortalHtml: function() {
 
        var softwareId = this.getParameter('sysparm_software_id');

var map = new GlideRecord('table _name');
map.addQuery('u_software', softwareId);
map.query();
if (map.next()) {
    var link = map.getValue('link fieled')
    var softwareName = map.getVlue('software_fieldname')
    var html = "" +
        "<div style='margin-top:8px;'>"

        +
        "  <div style='font-weight:600; margin-bottom:4px;'>" +
        "    Software name: <span>" + softwareName + "</span>" +
        "  </div>"

        +
        "  <div style='margin-bottom:10px;'>" +
        "    Link: <span style='font-family: monospace;'>" + link + "</span>" +
        "  </div>"

        +
        "  <div style='color:#b00020; font-weight:600; margin-bottom:6px;'>" +
        "    This product is already available in Company Portal." +
        "  </div>"

        +
        "  <div style='margin-bottom:6px;'>" +
        "    <a href='" + link + "' target='_blank' rel='noopener'>Click here</a>" +
        "    to access it and install the product by yourself!" +
        "  </div>"

        +
        "  <div>" +
        "    If you require installation support or need to install a specific version not available in the Company Portal, " +
        "    please select <b>YES</b> in the installation assistance question and specify the required version in the " +
        "    <b>Description</b> field." +
        "  </div>"

        +
        "</div>";
    return html;
}


},

type: 'SoftwarePortalAjax'
});





Create Onchange client script: Variable name: Software name(your lookup variable name)



function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading) return;




    var ga = new GlideAjax('SoftwarePortalAjax');

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

    ga.addParam('sysparm_software_id', newValue);



    ga.getXMLAnswer(function(answer) {

        if (answer) {

            g_form.setValue('portal_info', answer);

            g_form.setDisplay('portal_info', true);

        } else {

            g_form.setValue('portal_info', '');

            g_form.setDisplay('portal_info', false);

        }

    });

}

If this response addressed your question, please mark it as Helpful and accept it as the solution.

@mani55 

how many links are those?

if those are very limited you can create variables with those links and then show hide

what script did you start?

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

4 products and 4 link and also we need to through widget only we need to configure

pr8172510
Tera Guru

Hi @mani55,

Implemented using:

  • Custom mapping table
    (u_software_portal_mapping)
  • Catalog Item
    (Software Request Demo)
  • Lookup Select Box variable
    (Software Name)
  • HTML variable
    (Information)
  • Script Include
    (SoftwarePortalHelper)
var SoftwarePortalHelper = Class.create();
SoftwarePortalHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getSoftwareInfo: function() {

        var software = this.getParameter('sysparm_software');

        var gr = new GlideRecord('u_software_portal_mapping');

        gr.addQuery('u_software_name', software);
        gr.query();

        if (gr.next()) {

            return JSON.stringify({
                link: gr.u_portal_link.toString()
            });
        }

        return JSON.stringify({
            link: ''
        });
    },
    type: 'SoftwarePortalHelper'
});​
  •  onChange Catalog Client Script with GlideAjax
function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || !newValue)
        return;

    var ga = new GlideAjax('SoftwarePortalHelper');

    ga.addParam('sysparm_name', 'getSoftwareInfo');
    ga.addParam('sysparm_software', newValue);

    ga.getXMLAnswer(function(response) {

        var data = JSON.parse(response);

        var html = '';

        if (data.link) {

            html += '<div style="padding:10px;';
            html += 'border:1px solid #d9534f;';
            html += 'background:#fff5f5;';
            html += 'margin-top:10px;">';

            html += '<b>This product is already available in Company Portal.</b><br><br>';

            html += '<a href="' + data.link + '" target="_blank">';
            html += 'Click here to access it and install the product by yourself!';
            html += '</a><br><br>';

            html += 'If you require installation support or need to install a specific version not available in the Company Portal, ';
            html += 'please select YES in the installation assistance question and specify the required version in the Description field.';

            html += '</div>';
        }

        g_form.setValue('software_info', html);

    });
}
​



pr8172510_0-1779795916296.png