How do you set the markup of a Rich Text Label?

tdQ1w7xO6k
Giga Contributor

I have a catalog client script reading the contents of a lower Order variable and using it to append to a few URLs that should be displayed in a higher Order variable. Since rich text labels can have hyperlinks, it makes sense to use that. How do you set the markup of a rich text label in code? Right now nothing is displaying from using g_form.setValue().

3 REPLIES 3

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

.setLabelOf() will change the rich text label on ServicePortal but not in UI.

Example:

Rich Text Label definition

find_real_file.png

Client Script

function onLoad() {
	g_form.setLabelOf('rich_text_label', '<a title="ServiceNow" href="www.servicenow.com" rel="nofollow">ServiceNow</a>');
}

Result in Service Portal

find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

Rich label text may be changed in UI using DOM manipulation. DOM manipulation is not highly recommended because it may break when ServiceNow is versioned up.

Just will provide sample for completeness.

Following are the steps to change Rich label text using DOM manipulation, 

  1. Set "Isolate script" to false (unchecked).
  2. Get the ID of the Rich Text Label to change (usually can be found by right-clicking near the label and selecting "Inspect".
  3. Client script
    function onLoad() {
    	var g = gel('element.IO:6470cd6d2f6e8d509d10b2e72799b6b4');
    	g.innerHTML = '<a href="https://www.servicenow.com">ServiceNow</a>';
    }​

    find_real_file.png

Execution result:

find_real_file.png

 

This didn't work, but I found out while trying it that you can put links in an info message, which achieved the same intended effect. Thanks.