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

Ravi Gaurav
Giga Sage
Giga Sage

Can you give alert and check code seems to be correct ..

I am re-writing the script.. make sure backend name is correct. I tested in Personal Instance its working.

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

var deviceTypeValue = g_form.getValue('device_type');
alert('Device Type Value:', deviceTypeValue);

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';
break;
// Add more cases as needed
default:
deviceTypeLabel = 'Device';
}

alert('Device Type Label:', deviceTypeLabel);

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

g_form.setValue('short_description_1', "Lost/Stolen " + deviceTypeLabel + ' Reported By ' + requestedForValue);
} else {
alert('No record found for username.');
}
});
}

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


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 

 

This is the script I have tried which u have given , alerts i commented 

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

    var deviceTypeValue = g_form.getValue('device_type');
    //alert('Device Type Value:', deviceTypeValue);

    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';
            break;
            // Add more cases as needed
        default:
            deviceTypeLabel = 'Device';
    }

    //alert('Device Type Label:', deviceTypeLabel);

    g_form.getReference('username', function(requestedForRecord) {
        if (requestedForRecord) {
            var requestedForValue = requestedForRecord.name;
            //alert('Requested For:', requestedForValue);

            g_form.setValue('short_description_1', "Lost/Stolen " + deviceTypeLabel + ' Reported By ' + requestedForValue);
        } else {
            //alert('No record found for username.');
        }
    });
}

 

 Still it is not working . 

nameisnani_1-1724296458800.png

 

If you could see here short description is blank here .

nameisnani_0-1724296419219.png