UI Page GlideAjax not triggering when passing value from UI Macro/GlideModal using setPreference

Ajays0396044436
Giga Contributor

Hi Everyone,

I am working on a requirement where I created a custom button using a UI Macro and displayed it on the form using a Formatter.

When user clicks the button:

  1. A GlideModal opens
  2. A UI Page loads
  3. I pass a CyberGRX ID from UI Macro to UI Page using:

gm.setPreference("sysparm_grx_id", grx_id);

Inside the UI Page, I am able to retrieve and display the value successfully using:

<g>
var grxId = RP.getParameterValue('sysparm_grx_id');
</g>

and:

${grxId}

The issue:
I am trying to use this grxId inside client-side JavaScript in the UI Page and trigger a GlideAjax call, but the API/GlideAjax is not executing.

 

UI PAGE HTML code is: -

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:evaluate>
var grxId = RP.getParameterValue('sysparm_grx_id');
</g:evaluate>

<h2>CyberGRX ID:</h2> ${grxId}

<script>

var grxId = "${grxId}";

showData();

</script>

 

<div>
<!-- <p>"This is just a demo for review."</p> -->
<table border="1" style="width:100%; border-collapse:collapse; text-align:left;">
<thead>
<tr>
<th>Risk Domain</th>
<th>Domain Index</th>
<th>Domain Index Rating</th>
<th>Domain Impact</th>
<th>Domain Descriptiong</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>

 

</j:jelly>

 

 

and Client script code is like - 

 

function showData() {

    var gajax = new GlideAjax("GRX_ClientServerBridge");
    gajax.addParam("sysparm_name", "getAPIDetails"); // line no. `114 in clientserverbridge script.
    gajax.addParam("sysparm_record", g_form.getUniqueValue());
    // gajax.addParam("sysparm_customerID", g_form.getValue("grxId")); // here value change
    gajax.addParam("sysparm_customerID", grxId);
    gajax.getXML(AddRecordFromPortfolio1);

    function AddRecordFromPortfolio1(response) {

    try {
        //g_form.addErrorMessage("this part is not working! ");
        //console.log("this is not working");
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var data = JSON.parse(answer);
        console.log("Parsed Data:", data);
        var tbody = document.getElementById("tableBody");
           
            tbody.innerHTML = "";
            var rows = "";
            data.risk_domains.forEach(function(item) {
                rows += '<tr>' +

                    '<td>' + item.risk_domain_name + '</td>' +

                    '<td>' + item.risk_domain_index + '</td>' +

                    '<td>' + item.risk_domain_index_rating + '</td>' +

                    '<td>' + item.risk_domain_impact_rating + '</td>' +

                    '<td>' + item.risk_domain_description + '</td>' +

                    '</tr>';
                    });
                   
                tbody.innerHTML = rows;

        } catch (ex) {
            console.error("API Error: " + ex.message);
            }

    }

}
I am attaching the Screenshot also for this better understanding.Client script code.pnghtml code_.pngui macro button and grxid code .png
 I tried with different changes but still not getting any result, Please can anyone help me out, what i am missing here. and where i can do changes so it will work. 
 
Thankyou all members.
0 REPLIES 0