How to set URL within javascript

Kifrez
Kilo Guru

Hi,

I have a URL type field and I would like to set knowledge base article.

For example, I would like to show as per following KB012345
find_real_file.png

How do I achieve this using javascript within Workflow?

I have the following script

var instance = gs.getProperty('glide.servlet.uri');
var kbnumber = 'KB001234';
var kburl = instance + "kb_view.do?sysparm_article=" + kbnumber;

<a href="kburl" target="_blank">KB001234</a>
10 REPLIES 10

Hi @Ankur Bawiskar , yes, I would like to set a KB article hyperlink  in the URL field type.

I would like it to display KB0000 instead of the URL itself if possible.

DO you have any idea or shall I change the field type ?

 

var instance = gs.getProperty('glide.servlet.uri');
var kbnumber = 'KB0011609';
var kburl = instance + "kb_view.do?sysparm_article=" + kbnumber;
var setkblink = '[code]<a href="' + kburl + '" target="_blank">' + kbnumber + '</a>[code]';

g_form.setValue('u_kbarticle', 'setkblink', 'kbnumber');

Hi,

you can use this in the work notes which is journal field but for URL field type won't support that

using BR you can set this

var instance = gs.getProperty('glide.servlet.uri');
var kbnumber = 'KB0011609';
var kburl = instance + "kb_view.do?sysparm_article=" + kbnumber;
var setkblink = '[code]<a href="' + kburl + '" target="_blank">' + kbnumber + '</a>[code]';

curent.setValue('work_notes', setkblink);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Is there any other way? other field I can put the URL

Hi,

only journal fields supports link etc and not string fields

So there is only 1 option of using journal field

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

-O-
Kilo Patron
Kilo Patron

There would be a solution but it can be difficult to implement.

One could create:

- another field of type String and set it up to depend and the URL field

- a Formatter (and UI Macro) to display such combos (hide the URL field on load and display an anchor using the hidden URL field's value as the href attribute and its own value as the anchor text.

Actually this part is pretty easy and str8 fwd.

It would become complicated if one wanted to add editing capabilities.

In the scenario above, the WF would still set the URL field to the plain URL, and it would set the new String field to any desired text to be the label for the anchor.

On forms where you'd need the nice text to be shown instead of the URL you would add the Formatter. Everywhere else the URL field would still behave as a regular URL field and the href contained would still be the valid anchor.