How to create a hyper link in the text message

subbarayudu
Tera Contributor

How to create a hyper link when ever user click on VRA number it should be redirect to that page. How to achieve this requirement.

Thanks in advance. 

subbarayudu_0-1679584492608.png

 

5 REPLIES 5

Sonu Parab
Mega Sage
Mega Sage

Hello  @subbarayudu ,
Have a look this post https://www.servicenow.com/community/itsm-forum/how-to-add-hyperlink-in-additional-comments-field-in... 

I just wanted to conform, How to Additional Comment added?

 

Thank you

Additional comments are coming from Business rule, When ever  Vendor risk assessment  state becomes to 'response received' then we are setting the automated comments in the core_company table.

The following code is using for setting automated comments

(function executeRule(current, previous /*null when async*/ ) {
var parentVendor = current.vendor;
var vdr = current.vendor.name;
var core = new GlideRecord('core_company');
core.addQuery('sys_id', parentVendor);
core.query();
if (core.next()) {
var cdate = new GlideDateTime();
var num = current.number;
var suppid = current.vendor.u_supplier_id;
var str = cdate + ' ' + vdr + ' ' + num + ' Supplier ID: ' + suppid + ' Vendor Submitted Vendor Risk Assessment';
core.u_automated_comments = str;
core.update();
}
})(current, previous);

 

So i want that number field as a  hyperlink.

Sal12
Tera Expert

@subbarayudu 

You haven't shared, how your Automated Comments field is getting populated, so I am giving you a couple of samples to try (later in the post), but first I will give a general idea of how that's done.

 

General idea:

In a journal entry field (for example, the out of the box Work notes field in an incident record), you'd need to enter the [code][/code] tags around the code you wish to render as HTML.

 

Here's what I mean by that:

Work notes field image below of an incident record:

 

 

Sal12_5-1679595202706.png

 

 

Next, in the Work notes field, if I wrote, the code: 

Sal12_6-1679595248815.png

 

 

The same code written below, as it is in the above picture:

 

 

[code]
<a href='https://www.service-now.com' target='blank'>ServiceNow</a>
[/code]

 

 

Then, after saving the record, I will get this output, see the Activities which I marked with an arrow.

Sal12_7-1679595401890.png

 

If I click on that link, I will be redirected to this web page on a new tab.

Sal12_1-1679594616400.png

 

So that's the general idea.

 

Now, as I mentioned above, I will give you you a couple of samples to try, and here they are:

 

Sample 1:

Here, as an example, I will use a before (update) business rule, to update the Work notes field, when the Problem field is not empty.

 

 

Sal12_8-1679595633036.png

Sal12_9-1679595725248.png

 

The Script in the above picture is written below:

 

(function executeRule(current, previous /*null when async*/) {
	
	var problemSysId = current.problem_id;
	var problemNumber = current.problem_id.getDisplayValue();
	var message = gs.getMessage("[code] Click --> <a href='/problem.do?sys_id={0}' target='_blank'> {1}</a> to redirect to the problem record.[/code]", [problemSysId, problemNumber]);
								
	current.work_notes = message;

})(current, previous);

 

 

On my Incident record, under the Related Records related list, I have the PRB0040001, in the Problem field.

 

Sal12_10-1679595876082.png

 

Next, if I update the incident record, I will see the following has been updated by using the Work notes field and can be seen in the Activities.

 

Sal12_11-1679595997664.png

 

If I click on that link, I will be redirected to the problem record on a new tab.

Sal12_12-1679596060233.png

 

 

Sample 2:

If I'd write, in the work notes field directly, I will get the similar results, as shown in Sample 1.

 

 

[code]
Click --> <a href='/problem.do?sys_id=77861465970311107b51b4b3f153afda' target='_blank'>PRB0040001</a> to redirect to the problem record.
[/code]

 

 

So, these are samples to get a feel or idea on how to do that.

Additional comments are coming from Business rule, When ever  Vendor risk assessment  state becomes to 'response received' then we are setting the automated comments in the core_company table.

The following code is using for setting automated comments

(function executeRule(current, previous /*null when async*/ ) {
var parentVendor = current.vendor;
var vdr = current.vendor.name;
var core = new GlideRecord('core_company');
core.addQuery('sys_id', parentVendor);
core.query();
if (core.next()) {
var cdate = new GlideDateTime();
var num = current.number;
var suppid = current.vendor.u_supplier_id;
var str = cdate + ' ' + vdr + ' ' + num + ' Supplier ID: ' + suppid + ' Vendor Submitted Vendor Risk Assessment';
core.u_automated_comments = str;
core.update();
}
})(current, previous);

 

So i want that number field as a  hyperlink in the automate comments, so hoe i can write the business rule.