Passing JSON Response to Widget in Correct Format

bdsibert
Tera Contributor

I have developed a Widget based on many of the examples available in the community that displays results from an external REST API call. The widget reacts appropriately (it updates based on the selection in a field on the form), but I am having a difficult time figuring out how to display the results correctly on my catalog item HTML. 

Server Script

(function() {

    var r = new sn_ws.RESTMessageV2();
    r.setHttpMethod('get');
    r.setRequestHeader("Content-Type", "application/json");
    r.setMIDServer("DEV - MID Server 1");
    r.setEndpoint('https://test.com/acm/db/api/v1.0/users?pam_group=' + input.message);
    var response = r.execute();
    data.result = JSON.parse(response.getBody());

})();

Client Script

function($rootScope) {
    var c = this;
    $rootScope.$on("field.change", function(evt, parms) {
        if (parms.field.name == 'cyberark_selectpam_v2') {
            c.data.value1 = parms.newValue;
            c.data.message = c.data.value1;
            c.server.update();
        }
    });

}

HTML

<div>
   <p class="label label-info">
    These users are part of the selected PAM Group
  </p>
  </div>

<div>
<table>
   <tr style="background-color: white">
     <th style="background-color: #E8E8E8">Name
     </th>
     <tr ng-repeat="name in data.result">
       <td style="background-color:white">{{name}}//the name variable wrapped in double curly braces didn't show up when I use the code editor here. 
    </td>
  </tr>
  </table>

</div>

When I use the widget, I get results like this:

find_real_file.png

But I would like each individual to have their own row. How can I parse this to do that when the JSON returned is like this:

"data": [
"Damera, Murali",
"Kumar, Ashish",
"Sankaranarayanan, Karthikeyan",
"Venkatesan, Rajesh Kumar"
]

Thank you!

1 ACCEPTED SOLUTION

Hi,

I don't know all the specifics of your page, but...

I believe you should be able to add an additional condition with something like:

if (parms.field.name == 'cyberark_selectpam_v2' && $scope.page.g_form.getValue('field_name') == 'add_server') {

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

7 REPLIES 7

Hi,

I don't know all the specifics of your page, but...

I believe you should be able to add an additional condition with something like:

if (parms.field.name == 'cyberark_selectpam_v2' && $scope.page.g_form.getValue('field_name') == 'add_server') {

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you very much Allen--that did the trick!

Cheers!

Hi,

No problem. If any reply in this thread was also helpful, please also mark it as such.

Thanks and take care!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!