Need Assistance, want to populate portal URL variable OnChange of Application Name

Community Alums
Not applicable

Hello Community,

 

I need some assistance with a Service Catalog item I'm working on. I have two variables in my catalog item:

 

1. **Application Name**: A reference field to the CMDB CI Application table.

2. **Variable**: Newly created  variable (Not Sure which type need to used for my requirement)

 

I also have a portal URL variable in the application table. What I want to achieve is that when a user selects an application from the Application Name reference field, the 2nd variable should dynamically show a clickable link that says "For Portal Link Click here." This link should open the URL stored in the portal URL field of the selected application.

 

Could you please guide me on how I can proceed with this requirement? What type of variable should I use for the 2nd variable, and how can I ensure it updates dynamically based on the user's selection?

 

FYI:

Portal URL on Application Table 

Amit136581_0-1719387678650.png

 

 

 

Thank you in advance!

2 ACCEPTED SOLUTIONS

surajchacherkar
Mega Guru

Hi @Community Alums ,

 

Instead of creating 2nd variable try to use addInfoMessage and paas portal  clickable link in it.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks

Suraj

View solution in original post

surajchacherkar
Mega Guru

Hi @Community Alums ,

 

I have made same kind of requirement in my PDI,

 

Script Include:

 

var GetApplicationDetails = Class.create();
GetApplicationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getPortalUrl: function() {
        var appName = this.getParameter("sysparm_catupdtelevel2");
        var result = '';
        if (appName) {
            var grlevel2 = new GlideRecord("cmdb_ci");
            grlevel2.addQuery("sys_id", appName);
            grlevel2.query();
			var sysIdArrayL3 = [];
            if (grlevel2.next()) {
                var pURL = grlevel2.u_portal_url.toString();
                sysIdArrayL3.push(pURL);
                result = 'true';
            } else {
                result = 'false';
            }
			
        }
        var answerObj = {
            sysIdArrayL3: sysIdArrayL3,
            result: result
        };
        return JSON.stringify(answerObj); 
    },
    type: 'GetApplicationDetails'
});

 

 

Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var appName = g_form.getValue('application_name');
    if (appName) {
        var ga = new GlideAjax('GetApplicationDetails');
        ga.addParam('sysparm_name', 'getPortalUrl');
        ga.addParam('sysparm_catupdtelevel2', appName);
        ga.getXMLAnswer(function(answer) {
            var answerObj = JSON.parse(answer);
            if (answerObj.result === 'true') {
                var portalURL = answerObj.sysIdArrayL3;
                 g_form.addInfoMessage(' To proceed with Portal URL :<a href =' +portalURL+ 'target="_self">click here</a>','info');
			}

        });
    }
}

 

 

 

 

Its working fine in my PDI, Link is also clickable and its dynamic.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.


Thanks 

Suraj Chacherkar

ServiceNow Developer

 

View solution in original post

3 REPLIES 3

surajchacherkar
Mega Guru

Hi @Community Alums ,

 

Instead of creating 2nd variable try to use addInfoMessage and paas portal  clickable link in it.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks

Suraj

surajchacherkar
Mega Guru

Hi @Community Alums ,

 

I have made same kind of requirement in my PDI,

 

Script Include:

 

var GetApplicationDetails = Class.create();
GetApplicationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getPortalUrl: function() {
        var appName = this.getParameter("sysparm_catupdtelevel2");
        var result = '';
        if (appName) {
            var grlevel2 = new GlideRecord("cmdb_ci");
            grlevel2.addQuery("sys_id", appName);
            grlevel2.query();
			var sysIdArrayL3 = [];
            if (grlevel2.next()) {
                var pURL = grlevel2.u_portal_url.toString();
                sysIdArrayL3.push(pURL);
                result = 'true';
            } else {
                result = 'false';
            }
			
        }
        var answerObj = {
            sysIdArrayL3: sysIdArrayL3,
            result: result
        };
        return JSON.stringify(answerObj); 
    },
    type: 'GetApplicationDetails'
});

 

 

Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var appName = g_form.getValue('application_name');
    if (appName) {
        var ga = new GlideAjax('GetApplicationDetails');
        ga.addParam('sysparm_name', 'getPortalUrl');
        ga.addParam('sysparm_catupdtelevel2', appName);
        ga.getXMLAnswer(function(answer) {
            var answerObj = JSON.parse(answer);
            if (answerObj.result === 'true') {
                var portalURL = answerObj.sysIdArrayL3;
                 g_form.addInfoMessage(' To proceed with Portal URL :<a href =' +portalURL+ 'target="_self">click here</a>','info');
			}

        });
    }
}

 

 

 

 

Its working fine in my PDI, Link is also clickable and its dynamic.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.


Thanks 

Suraj Chacherkar

ServiceNow Developer

 

Community Alums
Not applicable

Thanks @surajchacherkar , I made some minor modification in code as per my requirement, Its working fine, Thanks for the help!