Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display Catalog Item Form variables in My Requests Widget

AnilREddy1408
Tera Contributor
 
1 REPLY 1

Rajesh Chopade1
Mega Sage

hi @AnilREddy1408 

To display catalog item form variables in the "My Requests" widget, you'll need to customize the widget to fetch and display the specific variables associated with each request.

 

you should open the "My Requests" widget and clone it first, It's best practice to clone the widget rather than modifying the original. 

 

Edit the 'Server script' to fetch catalog variables. You can have look of below sample script:

(function() {
    var requests = [];
    var gr = new GlideRecord('sc_request');
    gr.addQuery('requested_for', gs.getUserID());
    gr.orderByDesc('sys_created_on');
    gr.query();

    while (gr.next()) {
        var request = {
            sys_id: gr.sys_id.toString(),
            number: gr.number.toString(),
            state: gr.state.getDisplayValue(),
            requested_on: gr.sys_created_on.getDisplayValue()
        };

        // Fetch the related catalog item variables
        var variables = [];
        var itemGR = new GlideRecord('sc_item_option_mtom');
        itemGR.addQuery('request', gr.sys_id);
        itemGR.query();
        
        while (itemGR.next()) {
            var variableGR = new GlideRecord('sc_item_option');
            if (variableGR.get(itemGR.sc_item_option)) {
                variables.push({
                    name: variableGR.name.toString(),
                    value: itemGR.value.toString()
                });
            }
        }

        request.variables = variables;
        requests.push(request);
    }

    data.requests = requests;
})();

 

Then you need to modify the HTML template to display the variables, you can have reference of bellow HTML template for your reference:

<div ng-repeat="request in c.data.requests">
    <h4>Request Number: {{ request.number }}</h4>
    <p>Status: {{ request.state }}</p>
    <p>Requested On: {{ request.requested_on }}</p>
    <div>
        <h5>Variables:</h5>
        <ul>
            <li ng-repeat="variable in request.variables">
                {{ variable.name }}: {{ variable.value }}
            </li>
        </ul>
    </div>
</div>

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh