Modify Parent breadcrumb (Formatter)

vidhya_mouli
Giga Sage

In my parent breadcrumb, right now it displays only the number field.

pc.setLabelField("number");

 

I need to modify my Macro to display both the number field and first 15 characters of the short description.

Format: "<Number>:<15 first characters of Short Description>..."

How can I get it done?

 

vidhya_mouli_0-1678183737624.png

 

1 ACCEPTED SOLUTION

vidhya_mouli
Giga Sage

Was able to achieve this create a separate field (calculated field). Finally just displayed that field value in the breadcrumb.

View solution in original post

11 REPLIES 11

Sai Shravan
Mega Sage

Hi @vidhya_mouli ,

 

You can modify your macro to concatenate the "number" field and the first 15 characters of the "short_description" field using the following syntax:

pc.setLabel("<number>:" + current.short_description.slice(0, 15));

 

This code uses the JavaScript string concatenation operator + to combine the "number" field and the first 15 characters of the "short_description" field. The slice() method is used to extract the first 15 characters of the "short_description" field.

Note that you will need to replace the word "number" with the actual name of the number field in your ServiceNow instance. Additionally, assuming that the current variable is in scope and refers to the current record being displayed in the breadcrumb.

 

Regards,

Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

It is still not working. I am sharing my full code. Can you help me to modify this code.

 

<?xml version="1.0" encoding="utf-8"?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <j2:if test="$[!${ref_parent}.isNewRecord() ${AND} !${ref_parent}.parent.nil() ${AND} ${ref_parent}.parent.getRefRecord().isValidRecord()]">
        <g2:evaluate var="jvar_crumbs">
            //get real glide record
            var gr = new GlideRecord(${ref_parent}.getTableName());
            gr.get(${ref_parent}.getUniqueValue());

            //parent crumb functions - script include
            var pc = new ParentCrumbs(gr);
			//pc.setLabelField("number");
			pc.setLabelField(current.number + ":" + current.short_description.slice(0, 15));
			
            var crumbs = pc.getCrumbs();
            crumbs;

        </g2:evaluate>
        <j2:if test="$[!jvar_crumbs.nil()]">
            <td class="breadcrumb_container">
				<div style="overflow: visible">
					<label for="" dir="ltr" class="${jvar_cols_label} control-label">
						<span title="" class="label-text">${gs.getMessage("Parents")}</span>
					</label>
				</div>
				<div class="${jvar_cols_field} form-field input_controls" style="overflow: visible">
					<div class="parent-breadcrumbs-container">
						<g2:no_escape>
							$[jvar_crumbs]
						</g2:no_escape>
					</div>
				</div>
				<div class="${jvar_cols_addons}"></div>
            </td>
        </j2:if>
    </j2:if>
</j:jelly>

Hi @vidhya_mouli ,

You need to modify the following line of code 

pc.setLabelField(current.number + ":" + current.short_description.slice(0, 15));  to pc.setLabel(current.number + ":" + current.short_description.slice(0, 15) + "...");

 

Regards,
Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

I tried, but for some reason I am able to see the display only when I use setLableField. The display does not work for setLable.