how to get display value and sys id from server script to client controller in service portal

Priya75
Tera Contributor

Hi All,

 

I am sending data through server.get and trying to fetch the data from server side,  i want to display the data filled in a catalog in tabular form.

 

 

 

 

 

//Client Controller
c.getloc= function()
{
var loc=c.loc.displayValue;

if(loc==''){
c.cloudser='';
}
this.server.get({
action :"hostloc",
name: loc
}).then(function(response){
c.cloudser=response.data.cloudProvideList;
});

//Server script

if(input.action="hostloc"){
var location=input.name;
data.cloudProvideList=[];
var cloudService-{};
if(location='Public')
{
var gr=new GlideRecord("sn_capi_provider");
gr.addQuery("u_type" ,location );
gr.query();
while(gr.next())
{
cloudService.name=gr.getValue("name");
cloudService.value=gr.sys_id.toString();
data.cloudProvideList.push(cloudService);

}

 

 

 

 

 

 

 

 

 

i want to use the name in the tabular form but i am getting sys_id . how can i get the name and set it in the tabular form( HTML form) 

 

7 REPLIES 7

Weird
Mega Sage

Try updating your server script with "if(input && input.action == "hostloc") instead of "if(action=hostloc)"
Basically you're currently just assigning action (which doesn't exists in server) as hostloc (which doesn't exist) inside the condition.

After updating that your if will recognize the input and also you can specify that the input.action needs to be hostloc, so that in the future if you add additional inputs they won't trigger that every time.

Also, you have a comma before your push at the end of the server script. Change that to a dot.

//Client Controller
c.getloc = function() {
        var loc = c.loc.displayValue;

        if (loc == '') {
            c.cloudser = '';
        }
        this.server.get({
            action: "hostloc",
            name: loc
        }).then(function(response) {
            c.pList = response.data.serviceProList; //I assume this is supposed to be cloudProvideList
        });

        //Server script

        if (input && input.action == "hostloc") {
            var location = input.name;
            data.cloudProvideList = [];
            var cloudService - {};
            if (location = 'Public') {
                var gr = new GlideRecord("sn_capi_provider");
                gr.addQuery("u_type", location);
                gr.query();
                while (gr.next()) {
                    cloudService.name = gr.getValue("name");
                    cloudService.value = gr.sys_id.toString();
                    data.cloudProvideList.push(cloudService);
                }

Also notice that in your response you're setting c.pList as serviceProList. I assume you meant cloudProvideList, but it looks like your server script gets cut off, so I don't know if you have that somewhere else further below.

Priya75
Tera Contributor

Hi, 

 

I have changed the script; it was a typing mistake in the question.  i am getting the values in my original script.

i just want to know how do i get the display name from the server-side object to use in client side and set it.

have you tried, cloudService.name = gr.getDisplayValue("name"); to get display value?

Priya75
Tera Contributor

not working.