Onload Client Script to contain hyperlink "click here" for the URL - field is of type URL

Sachin Gavhane
Giga Guru

Hi Team,

I need "click here" hyper link for the field of type URL

in the below script--materiality_information is the field of type url

function onLoad() {


    var parentSysId = g_form.getValue('abc');


    if (parentSysId) {
        // Dynamically get the instance URL using document.location
        var instanceUrl = 'https://xyz.service-now.com/';

        var targetTable = 'https://xyz.service-now.com/x_mghmi_sw_mgmt_swm_req.do?sys_id=' + parentSysId + '&sysparm_view=';

        //var hyperlink = '<a href="' + targetTable + '" target="_blank">click here</a>';


        g_form.setValue('materiality_information', targetTable);
        //}
    }
requirement is: 
href is not working in client script, also how to make above link dynamic as per ServiceNow instance?

}
6 REPLIES 6

Chaitanya ILCR
Mega Patron

Hi @Sachin Gavhane ,

try this set the isolate script value to false

ChaitanyaILCR_0-1753200476269.png

script

function onLoad() {

    var parentSysId = g_form.getValue('abc');

    if (parentSysId) {
        // Dynamically get the instance URL using document.location
        var instanceUrl = location.origin;

        var targetTable = instanceUrl + '/x_mghmi_sw_mgmt_swm_req.do?sys_id=' + parentSysId + '&sysparm_view=';

        var hyperlink = '<a href="' + targetTable + '" target="_blank">click here</a>';
        g_form.addInfoMessage(hyperlink);

        g_form.setValue('materiality_information', targetTable);
    }

}

if this doesn't work

also check if the parentsysid is valid and put an alert inside if condition and check if it's getting inside the if block

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

@Chaitanya ILCR 

here "addinfomessage" shows correct hyperlink - with "click here"
but i want that click here for the field "materiality_information".

g_form.setValue('materiality_information', targetTable);

 

here setvalue is showing full url



materiality information field is of type url

Hi @Sachin Gavhane ,

 

you didn't attach the screenshot 

 

it shouldn't show full url? what's your expectation?

please share these things in details with some screenshots

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

SumanthDosapati
Mega Sage
Mega Sage

@Sachin Gavhane 

Use 'Rich Text Label' type of variable instead of URL type and use below sample script.

 g_form.setLabelOf('test_url', '<a title="ServiceNow" href="www.servicenow.com" rel="nofollow">Click Here</a>');

SumanthDosapati_0-1753200944935.png

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth