Need to make a variable as hyperlink in business rule

Talha3
Kilo Guru

@Allen Andreas 

 I have a requirement to make a variable value "Number" to be added to work notes(this part is working)

Second part is whenever user clicks on "demand number" from work notes they should be redirected on the service portal where this demand task exists so that non ITIL users can view the demand task.

Attached is the screenshot of business rule script:

find_real_file.png

 

find_real_file.png

As shown above need to make this Demand task number a hyperlink.

1 ACCEPTED SOLUTION

To create a hyperlink in the work notes, you can use the following:

gr.work_notes = '[code]<a href="' + gs.getProperty("glide.servlet.uri") + 'sp?id=ticket&table=dmn_demand&sys_id=' + current.getValue("sys_id") + '">' + current.getValue("number") + '</a> [/code]' + '\n Short Description: ' + current.getValue("short_description");

Keep in mind, also, for the above, you'd have to allow the [code] tag within your journal fields via this system property being set to: true

glide.ui.security.allow_codetag

You'd need to replace "sp" above in the code with the abbreviation for your service portal that you want to direct them to (if different).

Example of result:

find_real_file.png

and clicking link goes to:

find_real_file.png

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

7 REPLIES 7

Chandu Telu
Tera Guru
Tera Guru

Hi Talha,

Check the below links it will help you.

https://community.servicenow.com/community?id=community_question&sys_id=2a345bc9db5e1c90190b1ea66896193d

https://community.servicenow.com/community?id=community_question&sys_id=0cad1bc31bcbf8d49a53ece7624bcb43

 

Please Mark the answer if correct/helpful , if it helps

Kartik Sethi
Tera Guru
Tera Guru

Hi @Talha 

You can follow the links provided by @Sandeep Dutta or @Chandu Telu which can help you build solutions for your requirement.

You can also follow Formatting Journal Field, which provides the knowledge of Tags that can be used in Journal fields.

For your requirement you need to make slight changes to your business rule:

var msg = '';

//Directly get the Parent GlideRecord Object
if(current.parent) {
	var parentGr = current.parent.getRefRecord();
	var htmlStart = '[code]',
		htmlEnd = '[/code]',
		baseUrl = '/portal_name?id=demand_page_name&sys_is=';
	
	msg += htmlStart + '<a href=">' + baseUrl + parentGr.getValue('sys_id') + '" target="_blank">' + parentGr.getValue('number') + '\n';
	msg += 'Short Description: ' + current.getValue('short_description') + '\n';
	msg += 'Description: ' + current.getValue('description') + '\n';
	msg += 'Created By: ' + current.getValue('sys_created_by');
	//Add all the required details
	msg += .
	.
	.
	.
	.
	
	//Make sure to close the End tag
	msg += htmlEnd;
}

if(msg) {
	gr.work_notes = msg;
	gr.update();
}

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Hi @Talha 

 

There is a miss in my code, please find the updated code below:

var msg = '';

//Directly get the Parent GlideRecord Object
if(current.parent) {
	var parentGr = current.parent.getRefRecord();
	var htmlStart = '[code]',
		htmlEnd = '[/code]',
		baseUrl = '/portal_name?id=demand_page_name&sys_is=';

	//Closing Anchor tag was missed earlier
	msg += htmlStart + '<a href=">' + baseUrl + parentGr.getValue('sys_id') + '" target="_blank">' + parentGr.getValue('number') + '</a>\n';
	msg += 'Short Description: ' + current.getValue('short_description') + '\n';
	msg += 'Description: ' + current.getValue('description') + '\n';
	msg += 'Created By: ' + current.getValue('sys_created_by');
	//Add all the required details
	msg += .
	.
	.
	.
	.
	
	//Make sure to close the End tag
	msg += htmlEnd;
}

if(msg) {
	gr.work_notes = msg;
	gr.update();
}

 

Please try this code and it will work for you.

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik