2.2.difference behaviour b/w platform and in portal

nameisnani
Mega Sage

Hi Team , 

 

 

There is a difference behavior between Portal and Platform ends. 

 

We have catalog called Lost or Stolen Device. Based on device type, a Short description is populating .

 

For example, if I choose device type is 'Laptop' >> In short description field, it is populating like this, i.e. [ Lost/Stolen Laptop Report] [By requestor for name 

 

For this, i have written client script.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var deviceTypeValue = g_form.getValue('device_type');

    g_form.getReference('requested_for', function(requestedForRecord) {
        var requestedForValue = requestedForRecord.name;

        g_form.setValue('short_description_1', "Lost/Stolen " + deviceTypeValue + ' ' + " Reported By " + requestedForValue);
    });
}

 

 

 

Now , the problem I am facing is that this is working fine in portal, but when we are checking from the platform , it is not working .

 

If you could see in the below screenshot ,from the portal and platform  in the short description field, Device Type backend name is showing instead of label .

 

Portal View 

nameisnani_2-1724207052812.png

 

 

 

Platform view 

nameisnani_1-1724206916014.png

 

 

The Result should come like this 

nameisnani_3-1724207119659.png

 In both Platform and in portal .

 

@Ravi Gaurav 

 

can anyone please help me here , what changes should i need to do in my script .

11 REPLIES 11

Vaibhav127
Tera Guru

Hi @nameisnani ,

 

getvalue always returns the internal name of the choice, it may be the case that for laptop the internal and display value is same and for mobile it is different.

 

To get the display value of selectbox on portal try this.

var dv = g_form.getDisplayValue('select_box');

Ravi Gaurav
Giga Sage
Giga Sage

Hello isani,

Please use the below code it will work.

First of all we can't use getDisplayValue () in client script so, Use the below and mark help and accept the solution.
you have to use case wise basis like the below:-

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var deviceTypeValue = g_form.getValue('devicetype');

var deviceTypeLabel = '';
switch(deviceTypeValue) {
case 'mobile_phone':
deviceTypeLabel = 'Mobile Phone';
break;
case 'laptop':
deviceTypeLabel = 'Laptop';
break;
// Add more cases as needed
default:
deviceTypeLabel = 'Device';
}

g_form.getReference('username', function(requestedForRecord) {
var requestedForValue = requestedForRecord.name;
console.log('Requested For:', requestedForValue);

g_form.setValue('short_descr', "Lost/Stolen " + deviceTypeLabel + ' ' + " Reported By " + requestedForValue);
});
}





 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Hi @Ravi Gaurav , 

 

I have made changes in my script 

nameisnani_0-1724232015105.png

nameisnani_1-1724232084806.png

nameisnani_2-1724232369395.png

 

 

'@Ravi Gaurav  I don't know what was mistake here . not working as per my requirement . please help me here 

share your script please !!

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

@Ravi Gaurav 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var deviceTypeValue = g_form.getValue('device_type');

    var deviceTypeLabel = '';
    switch (deviceTypeValue) {
        case 'mobile_phone':
            deviceTypeLabel = 'Mobile Phone';
            break;
        case 'laptop':
            deviceTypeLabel = 'Laptop';
            break;
        case 'other_specify_desp':
            deviceTypeLabel = 'Other - Specify in Description'

            // Add more cases as needed
        default:
            deviceTypeLabel = 'Device';
	}



            g_form.getReference('username', function(requestedForRecord) {
                var requestedForValue = requestedForRecord.name;
                console.log('Requested For:', requestedForValue);

                g_form.setValue('short_description_1', "Lost/Stolen " + deviceTypeLabel + ' ' + " Reported By " + requestedForValue);
            });
    }