Custom breadcrumbs for Cost Plan

Ahyel Libunao1
Tera Contributor

Hi, 

 

I am trying to create custom breadcrumbs via formatter and UI macro for the Cost Plan record but my scripts dont work. 

 

My final output should be like this but in Cost Plan record. 

AhyelLibunao1_0-1696830437883.png

The Breadcrumbs should make the Project/Demand (field name: task) short description visible as its parent record. 

AhyelLibunao1_1-1696830549455.png

 

 

This is my Script Include: 

var CostPlanBreadcrumbs = Class.create();

CostPlanBreadcrumbs.prototype = {
    initialize: function() {},

    // Function to generate the breadcrumbs for a cost plan record
    getBreadcrumbs: function(costPlanGR) {
        var breadcrumbs = [];

        // Add the cost plan record itself to the breadcrumbs
        breadcrumbs.push(costPlanGR.getDisplayValue());

        // Get the parent task reference field (adjust field name as needed)
        var parentTaskRef = costPlanGR.getValue('task'); // Replace with the correct field name

        // Check if the parent task reference is not empty
        if (parentTaskRef) {
            // Fetch the parent task record
            var parentTaskGR = new GlideRecord('task'); // Replace with the actual table name
            if (parentTaskGR.get(parentTaskRef)) {
                // Add the parent task name to the breadcrumbs
                breadcrumbs.unshift(parentTaskGR.getDisplayValue());
            }
        }

        return breadcrumbs.join(' > ');
    },

    type: 'CostPlanBreadcrumbs'
};
 
 
While this is my UI Macro:
<?xml version="1.0" encoding="utf-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <j2:if test="$[!${ref_cost_plan}.isNewRecord() ${AND} !${ref_cost_plan}.gs.nil() ${AND} ${ref_cost_plan}.task.getRefRecord().isValidRecord()]">
        <g2:evaluate var="breadcrumbs">
            var costPlanGR = new GlideRecord(gs.esc(ref_cost_plan.getTableName()));
            costPlanGR.get(gs.esc(ref_cost_plan.getUniqueValue()));

            var breadcrumbsUtil = new CostPlanBreadcrumbs();
            var result = breadcrumbsUtil.getBreadcrumbs(costPlanGR);
            result;
        </g2:evaluate>

        <j2:if test="${!gs.nil(breadcrumbs)}">
            <span>${breadcrumbs}</span>
        </j2:if>
    </j2:if>
</j:jelly>
 
Not really familiar yet to jelly scripting though. Would like to check for some recommendations. Would really appreciate. 
 
Thank you!
0 REPLIES 0