The CreatorCon Call for Content is officially open! Get started here.

Get Project State instead of phase on Analytics

nowitsvashu
Tera Guru

nowitsvashu_0-1759941796210.png

Hi ServiceNow Community, my requirement is to get project state instead of phase(first column) on the project summary custom dashboard present on analytics link of project workspace. How can it be configured using the UI builder?

1 REPLY 1

M Iftikhar
Giga Sage

Hello @nowitsvashu,
You can achieve this by configuring the Project Summary custom dashboard using the
UI Builder. Follow the steps below: 

Steps: 

1. Open the dashboard in UI Builder 
Navigate to: 

https://<your-instance>.service-now.com/now/builder/ui/edit/experience/8adc36706f01011089060168e25b3... 

 

2. Duplicate the Phase container 

  • In the structure tree, locate the Phase container. 
  • Duplicate it and rename the components to State. 
  • Hide the visibility of the original Phase component. 

MIftikhar_0-1760018546890.png

 

 3. Modify the data source 

  • Go to the Project Workspace Script Include and edit the getDashboardData function and add the _getStateChoices function below _getPhaseChoices function : 

https://<your-instance>.service-now.com/now/nav/ui/classic/params/target/sys_script_include.do%3Fsys... 

Functions

 
getDashboardData: function(projectId, table) { 

        let gr = new GlideRecord(table); 
        let phaseChoiceListArr = this._getPhaseChoices(table); 
        // Add a new helper for state choices 
        let stateChoiceListArr = this._getStateChoices(table); 
        gr.get(projectId); 
        if (!gr.canRead()) { 
            return { 
                status: 'error', 
                statusCode: '403' 
            }; 
        } 
        //caluclate time elapsed 
        let timeElapsedCal = new global.TimeElapsedCalculation(); 
        let timeElapsed = timeElapsedCal.calculateTimeElapse(projectId), 
            percentComplete, phase, projStatusColor, projStatus, state; 
        const executionTypeId = this._getphaseTypeId(gr.getValue('execution_type')); 
        percentComplete = gr.getDisplayValue('percent_complete'); 
        phase = gr.getValue('phase'); 
        projStatus = gr.getDisplayValue('status'); 
        projStatusColor = gr.getValue('status'); 
        //  Capture the record's state 
        state = gr.getDisplayValue('state'); 
        return { 
            phase, 
            phaseChoiceListArr, 
            state, //  added 
            stateChoiceListArr, 
            executionTypeId, 
            projStatus, 
            projStatusColor, 
            percentComplete, 
            timeElapsed 
        }; 
    }, 
    _getPhaseChoices: function(table) { 
        let phaseChoiceListArr = [], 
            phaseChoice, phaseChoiceList = GlideChoiceList.getChoiceList(table, 'phase'); 
        for (var i = 0; i < phaseChoiceList.size; i++) { 
            phaseChoice = phaseChoiceList.getChoice(i); 
            let phaseObj = { 
                id: phaseChoice.getValue(), 
                label: phaseChoice.getLabel(), 
                progress: "none", 
                disabled: "none" 
            }; 
            phaseChoiceListArr.push(phaseObj); 
        } 
        return phaseChoiceListArr; 
    }, 
    _getStateChoices: function(table) { 
        let stateChoiceListArr = [], 
        stateChoice,stateChoiceList = GlideChoiceList.getChoiceList(table, 'state'); 
       for (var i = 0; i < stateChoiceList.size; i++) { 
            stateChoice = stateChoiceList.getChoice(i); 
            let stateObj = { 
                id: stateChoice.getLabel(), 
                label: stateChoice.getLabel(), 
                progress: "none", 
                disabled: "none" 
            }; 
            stateChoiceListArr.push(stateObj); 
        } 
        return stateChoiceListArr; 
    }, 

 4.Update the State stepper configuration 

  • In UI Builder, open the State_displayValue_stepper configuration. 
  • Update both the Items and Selected item fields with the required state-based data logic. 

Items: 

/** 
 * @param {params} params 
 * @param {api} params.api 
 * @param {TransformApiHelpers} params.helpers 
 */ 
function evaluateProperty({ 
    api, 
    helpers 
}) { 
    const selectedItem = api.data.get_project_dashboard_data_1.output.result.state; 
    const stateChoiceList = api.data.get_project_dashboard_data_1.output.result.stateChoiceListArr; 
    for (let i = 0; i < stateChoiceList.length; i++) { 
        if (selectedItem != stateChoiceList[i]["id"] || selectedItem === stateChoiceList[stateChoiceList.length - 1]["id"]) { 
            stateChoiceList[i]["progress"] = "done"; 
        } else break; 
    } 
    return stateChoiceList; 
} 

Selected Item:


/** 
 * @param {params} params 
 * @param {api} params.api 
 * @param {TransformApiHelpers} params.helpers 
 */ 

function evaluateProperty({ 
    api, 
    helpers 
}) { 

    const stateType = api.data.get_project_dashboard_data_1.output.result.state; 
    const stateChoiceList = api.data.get_project_dashboard_data_1.output.result.stateChoiceListArr; 
    const selectedItem = (stateType === stateChoiceList[stateChoiceList.length-1]["id"]) ? "" : stateType; 

    return selectedItem; 
} 

 

MIftikhar_1-1760018546893.png

 

 5. Save and verify 

  • Save your configuration. 
  • Open the Project Workspace and check the Analytics > Project Summary dashboard to confirm the project state now appears instead of the phase. 

 

 

MIftikhar_2-1760018546894.png

 

 

If my response helped, please mark it as the accepted solution so others can benefit as well.  

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.