How to set URL within javascript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 12:35 AM
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
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>
- Labels:
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 01:55 AM
Hi
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 02:04 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 02:52 AM
Is there any other way? other field I can put the URL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 02:58 AM
Hi,
only journal fields supports link etc and not string fields
So there is only 1 option of using journal field
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 04:00 AM
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.