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.

Extracting Parameters (sysID) from UI Page URL

shayna
Tera Contributor

I am working on extracting the sysparm_targetCompanyID from a UI Page URL.

Here's the setup: I have two UI Pages. The first UI Page serves as a dashboard displaying a grid of cards, with each card representing a customer. When a card is clicked, it redirects to a second UI Page, passing the sys_id of the company as part of the URL, to display detailed information about that company.

The second UI Page is built using Jelly. While I can successfully retrieve the sys_id using standard code in the client script section, I am unable to assign the value to the targetCompanyID variable. Any attempt results in a "Reference Error," preventing the company data from being displayed.

Here is an example of the URL I am trying to extract the sysparm_targetCompanyID from:

<a href="https://instancenamedev.service-now.com/ui_page.do?sys_id=1610e12947965e5020ed43f4116d439e&amp;syspa...}" target="_blank" style="text-decoration: none; color: inherit;">

 

I am thinking the problem is getting it to work using Jelly, not sure if i need to use j:set or something else. If anyone can point me in the right direction, much appreciated, thank you. 

 

Also, using a hard code sysid DOES work, no problem, everything shows for the company. I hope I provided enough information. 

---

var data = {};
       
       //var targetCompanyID = "${jvar_targetCompanyID}"; // for example
        //var targetCompanyID = "b66f310b93bd0250b0153b6a7bba10bd";
 
 
        var grProject = new GlideRecord('pm_project');
        grProject.addQuery("active", true);
        grProject.addQuery("company", targetCompanyID);
        grProject.query();
 
        while (grProject.next()) {
        var companyID = grProject.getValue('company');
        var companyName = grProject.company.getDisplayValue();
        var projectSysID = grProject.getValue('sys_id');
 
        if (!data[companyID]) {
        data[companyID] = {
        name: companyName,
        risks: [],
        issues: [],
        actions: [],
        decisions: [],
        proddowns: []
        };
        }
 
        var grRisk = new GlideRecord('risk');
        grRisk.addQuery('task', projectSysID);
        grRisk.query();
        while (grRisk.next()) {
        data[companyID].risks.push({
        number: grRisk.getValue('number'),
        task: grRisk.getDisplayValue('task'),
        project: grProject.getValue('short_description'),
        phase: grProject.getValue('u_project_phase'),
        shortDescription: grRisk.getValue('short_description'),
        description: grRisk.getValue('description'),
        created: grRisk.getValue('sys_created_on'),
        dueDate: grRisk.getValue('due_date'),
        probability: grRisk.getValue('probability'),
        impact: grRisk.getValue('impact'),
        state: grRisk.getDisplayValue('state'),
        assignedTo: grRisk.getDisplayValue('assigned_to'),
        mitigationPlan: grRisk.getValue('mitigation_plan'),
        workNotes: grRisk.getValue('work_notes')
        });
        }
 
        var grIssue = new GlideRecord('issue');
        grIssue.addQuery('parent', projectSysID);
        grIssue.query();
        while (grIssue.next()) {
        data[companyID].issues.push({
        number: grIssue.getValue('number'),
        shortDescription: grIssue.getValue('short_description'),
        impact: grIssue.getValue('impact'),
        priority: grIssue.getDisplayValue('priority'),
        assignedTo: grIssue.getDisplayValue('assigned_to'),
        dueDate: grIssue.getValue('due_date'),
        state: grIssue.getDisplayValue('state'),
        parent: grIssue.getDisplayValue('parent')
        });
        }
 
        var grAction = new GlideRecord('project_action');
        grAction.addQuery('parent', projectSysID);
        grAction.query();
        while (grAction.next()) {
        data[companyID].actions.push({
        number: grAction.getValue('number'),
        shortDescription: grAction.getValue('short_description'),
        impact: grAction.getValue('impact'),
        priority: grAction.getDisplayValue('priority'),
        assignedTo: grAction.getDisplayValue('assigned_to'),
        dueDate: grAction.getValue('due_date'),
        state: grAction.getDisplayValue('state'),
        parent: grAction.getDisplayValue('parent')
        });
        }
 
        // Query decisions related to this project
        var grDecision = new GlideRecord('dmn_decision');
        grDecision.addQuery('parent', projectSysID); // Assuming 'parent' relates decisions to the project
        grDecision.query();
        while (grDecision.next()) {
        data[companyID].decisions.push({
        number: grDecision.getValue('number'),
        shortDescription: grDecision.getValue('short_description'),
        state: grDecision.getDisplayValue('state'),
        priority: grDecision.getDisplayValue('priority'),
        assignedTo: grDecision.getDisplayValue('assigned_to'),
        created: grDecision.getValue('sys_created_on'),
        dueDate: grDecision.getValue('due_date'),
        decisionOutcome: grDecision.getValue('decision_outcome'), // Example custom field
        notes: grDecision.getValue('decision_notes') // Example custom field
        });
        }
 
        // Query ProdDown related to this project
        var grProdDown = new GlideRecord('u_incident_pd');
        grProdDown.addQuery('parent', projectSysID); // Assuming 'parent' relates prod down incidents to the project
        grProdDown.query();
        while (grProdDown.next()) {
        data[companyID].proddowns.push({
        number: grProdDown.getValue('number'),
        shortDescription: grProdDown.getValue('short_description'),
        priority: grProdDown.getDisplayValue('priority'),
        assignedTo: grProdDown.getDisplayValue('assigned_to'),
        state: grProdDown.getDisplayValue('state'),
        created: grProdDown.getValue('sys_created_on'),
        updated: grProdDown.getValue('sys_updated_on'),
        resolutionNotes: grProdDown.getValue('close_notes'), // Example field for resolution notes
        workNotes: grProdDown.getValue('work_notes') // Example field for work notes
        });
        }
        }
 
        var tableData = [];
        for (var key in data) {
        tableData.push({
        companyID: key,
        name: data[key].name,
        risks: data[key].risks,
        issues: data[key].issues,
        actions: data[key].actions,
        decisions: data[key].decisions,
        proddowns: data[key].proddowns
        });
        }
 
        tableData;
 
 
 
the following is an example of the table formatting to display data. 
<div class="container my-5 p-4 bg-light rounded shadow">
        <!-- Header Section -->
        <div class="text-center mb-4">
            <h2 class="fw-bold">Profile View</h2>
        </div>

        <!-- Company Section -->
        <j:forEach var="jvar_row" items="${jvar_tableData}">
            <!-- Company Header -->
            <div class="bg-primary text-white p-3 rounded mb-4">
                <h3 class="m-0">${jvar_row.name}</h3>
            </div>

            <!-- Risk Section -->
            <div class="bg-secondary text-white p-2 rounded mb-3">
                <h5 class="m-0">Risks</h5>
            </div>
            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead class="table-light">
                        <tr>
                            <th>Number</th>
                            <th>Project#</th>
                            <th>Project Name</th>
                            <th>Phase</th>
                            <th>Short Description</th>
                            <th>Description</th>
                            <th>Created</th>
                            <th>Due Date</th>
                            <th>Probability</th>
                            <th>Impact</th>
                            <th>State</th>
                            <th>Assigned To</th>
                            <th>Mitigation Plan</th>
                            <th>Work Notes</th>
                        </tr>
                    </thead>
                    <tbody>
                        <j:forEach var="jvar_risk" items="${jvar_row.risks}">
                            <tr>
                                <td>${jvar_risk.number}</td>
                                <td>${jvar_risk.task}</td>
                                <td>${jvar_risk.project}</td>
                                <td>${jvar_risk.phase}</td>
                                <td>${jvar_risk.shortDescription}</td>
                                <td>${jvar_risk.description}</td>
                                <td>${jvar_risk.created}</td>
                                <td>${jvar_risk.dueDate}</td>
                                <td>${jvar_risk.probability}</td>
                                <td>${jvar_risk.impact}</td>
                                <td>${jvar_risk.state}</td>
                                <td>${jvar_risk.assignedTo}</td>
                                <td>${jvar_risk.mitigationPlan}</td>
                                <td>${jvar_risk.workNotes}</td>
                            </tr>
                        </j:forEach>
                    </tbody>
                </table>
            </div>

 
             

---

1 REPLY 1

jcmings
Mega Sage

Try $sp.getParameter('sys_id') in the server script. You can assign it to a data object (e.g. data.sys_id = $sp.getParameter('sys_id') and then access that in the client script with $scope.data.sys_id).