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

URL link in field message when option is selected in dropdown list on catalog item not

Arjun Reddy Yer
Tera Guru

can you help me @Vasantharajan N 

As I tried with below script URL is visible only for me remaining user it's not.

 

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

    if (newValue == 'No') {
        var url = 'https://mylink.to.cataog/form';
var url = 'https:/un_sp?id=sc_cat_item&sys_id=73d9ec14db0de380fc597c57f49619df&sysparm_category=34bb6f54db650740f91e7aecbf961929' //my URL 

        g_form.showFieldMsg("approvals", "this will be removed"); // this field msg will be overwritten by the below DOM manipulation code
		var variable_sys_id = "eedbb8b247ca3110b3b3b477536d4340"; //Variable sys id in which we need to display the message.
        var x = gel('IO:'+variable_sys_id+'_fieldmsg');
        x.innerHTML = '<div class="fieldmsg notification notification-info">' + 
		"<p> <b> Available options </b> </p> "+
		"<p> - Option A </p>"+
		"<p> - Option B </p>"+
		"<p><a href='" + url + "' target='_blank' >Link to form</a></p>" + '</div>';
    } else {
        g_form.hideFieldMsg("approvals");
    }

 

For Me:

ArjunReddyYer_1-1700815887465.png

For Other Users:

ArjunReddyYer_0-1700815803058.png

 

1 ACCEPTED SOLUTION

@Arjun Reddy Yer - Please find the updated script for your reference. Please make the necessary changes as per your variable names.

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

    var portal = top.location.href;
    if (newValue == 'No') {
        var url = 'https://mylink.to.cataog/form';

        g_form.showFieldMsg("approvals", "this will be removed"); // this field msg will be overwritten by the below DOM manipulation code

        if (portal.indexOf("servicecatalog_cat_item_view") == -1) {            
			showFmsg(); // Show field message on Service Portal
        } else {
            var variable_sys_id = "eedbb8b247ca3110b3b3b477536d4340"; //Variable sys id in which we need to display the message.
            var x = gel('IO:' + variable_sys_id + '_fieldmsg');
            x.innerHTML = '<div class="fieldmsg notification notification-info">' +
                "<p> <b> Available options </b> </p> " +
                "<p> - Option A </p>" +
                "<p> - Option B </p>" +
                "<p><a href='" + url + "' target='_blank' >Link to form</a></p>" + '</div>';
        }

    } else {        
		if (portal.indexOf("servicecatalog_cat_item_view") == -1) {
			hideFmsg(); // Hide field message on Service Portal
        }else{
			g_form.hideFieldMsg("approvals");
		}
		
    }

	function hideFmsg(){
		var variable_name = 'approvals';
        var eleId = 'sp_formfield_' + variable_name + '_fieldmsgs_container';

        var approvalEle = top.document.getElementById(eleId);
		approvalEle.innerHTML = '';
	}

    function showFmsg() {
		//g_form.showFieldMsg("approvals", "Updated");
		
        var variable_name = 'approvals';
        var eleId = 'sp_formfield_' + variable_name + '_fieldmsgs_container';

        var approvalEle = top.document.getElementById(eleId);
        approvalEle.innerHTML = '<div ng-repeat="message in field.messages | unique: \'message\'" class="wrapper-xs r m-t-xs ng-binding ng-scope bg-info" ng-class="{\'bg-danger\': message.type == \'error\', \'bg-warning\': message.type == \'warning\', \'bg-info\': message.type == \'info\'}" style="">' +
            "<p> <b> Available options </b> </p> " +
            "<p> - Option A </p>" +
            "<p> - Option B </p>" +
            "<p><a href='" + url + "' target='_blank' >Link to form</a></p>" + '</div>';

    }
}

 Result in Service Portal

VasantharajanN_0-1700836411915.png

 


Thanks & Regards,
Vasanth

View solution in original post

3 REPLIES 3

Vasantharajan N
Giga Sage
Giga Sage

@Arjun Reddy Yer - The script provided will work for the platform view not on the Service Portal / ESC. If it's to work on the service portal/esc then we need to make further change


Thanks & Regards,
Vasanth

Can you please help me to get it work on Service Portal/ESC

@Arjun Reddy Yer - Please find the updated script for your reference. Please make the necessary changes as per your variable names.

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

    var portal = top.location.href;
    if (newValue == 'No') {
        var url = 'https://mylink.to.cataog/form';

        g_form.showFieldMsg("approvals", "this will be removed"); // this field msg will be overwritten by the below DOM manipulation code

        if (portal.indexOf("servicecatalog_cat_item_view") == -1) {            
			showFmsg(); // Show field message on Service Portal
        } else {
            var variable_sys_id = "eedbb8b247ca3110b3b3b477536d4340"; //Variable sys id in which we need to display the message.
            var x = gel('IO:' + variable_sys_id + '_fieldmsg');
            x.innerHTML = '<div class="fieldmsg notification notification-info">' +
                "<p> <b> Available options </b> </p> " +
                "<p> - Option A </p>" +
                "<p> - Option B </p>" +
                "<p><a href='" + url + "' target='_blank' >Link to form</a></p>" + '</div>';
        }

    } else {        
		if (portal.indexOf("servicecatalog_cat_item_view") == -1) {
			hideFmsg(); // Hide field message on Service Portal
        }else{
			g_form.hideFieldMsg("approvals");
		}
		
    }

	function hideFmsg(){
		var variable_name = 'approvals';
        var eleId = 'sp_formfield_' + variable_name + '_fieldmsgs_container';

        var approvalEle = top.document.getElementById(eleId);
		approvalEle.innerHTML = '';
	}

    function showFmsg() {
		//g_form.showFieldMsg("approvals", "Updated");
		
        var variable_name = 'approvals';
        var eleId = 'sp_formfield_' + variable_name + '_fieldmsgs_container';

        var approvalEle = top.document.getElementById(eleId);
        approvalEle.innerHTML = '<div ng-repeat="message in field.messages | unique: \'message\'" class="wrapper-xs r m-t-xs ng-binding ng-scope bg-info" ng-class="{\'bg-danger\': message.type == \'error\', \'bg-warning\': message.type == \'warning\', \'bg-info\': message.type == \'info\'}" style="">' +
            "<p> <b> Available options </b> </p> " +
            "<p> - Option A </p>" +
            "<p> - Option B </p>" +
            "<p><a href='" + url + "' target='_blank' >Link to form</a></p>" + '</div>';

    }
}

 Result in Service Portal

VasantharajanN_0-1700836411915.png

 


Thanks & Regards,
Vasanth