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.

nameisnani_0-1723788833270.png

 

 

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

    var reqFor = g_form.getDisplayValue('requested_for');
    var newvall = g_form.getDisplayValue('device_type'); //replace with the backend name of device type field


    //g_form.setValue('short_description_1', newvall +' '+ ": Device Type " + ' ' + " Reported By " + reqFor);
    g_form.setValue('short_description_1', "Lost/Stolen " + newvall + ' ' + " Reported By " + reqFor);





}

nameisnani_1-1723788833267.png

 

 

 

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 , in the short description field, the requestor for name is not populating .

 

nameisnani_2-1723788833269.png

 

can anyone please help me with this issue , where i have to update in my scirpt? 

 

Please help what was the mistake , and where should i update ?

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

The below should work :-

 

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);
});
}

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


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/

View solution in original post

7 REPLIES 7

Brad Warman
Giga Sage

I think for core UI you need to use getDisplayBox() instead of getDisplayValue()

 

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/client/c_GlideFormAPI

 

@Brad Warman  Thanks for your quick reply. Could you please provide me with the updated script? 

@Brad Warman 

// function onChange(control, oldValue, newValue, isLoading) {

//     if (isLoading || newValue == '') {
//         return;
//     }

//     var reqFor = '';
//     var newvall = '';

//     if (window == null) {
//         // Service Portal UI
//         reqFor = g_form.getDisplayValue('requested_for');
//         newvall = g_form.getDisplayValue('device_type');
//     } else {
//         // Core UI
//         reqFor = g_form.getDisplayBox('requested_for').value;
//         newvall = g_form.getDisplayBox('device_type').value;
//     }

//     g_form.setValue('short_description_1', "Lost/Stolen " + newvall + ' ' + " Reported By " + reqFor);

// }

 I have update like this , still not working . could you please what was the mistake i did here .

Ravi Gaurav
Giga Sage
Giga Sage

The issue you're facing could be due to differences in how the platform and portal handle client scripts, particularly in how g_form.getDisplayValue() behaves. Here are a few steps to troubleshoot and fix the issue:

1. Check the Field Names:

  • Ensure that the field names used in the script (requested_for and device_type) are correct and consistent across both the platform and the portal.

2. Use g_form.getValue() Instead of g_form.getDisplayValue() for Platform:

  • The getDisplayValue() method returns the display value of the field, which might work differently between the portal and platform. Instead, try using g_form.getValue() for the requested_for field, and then manually fetch the display value using a GlideAjax call if needed:
    function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } var reqForSysId = g_form.getValue('requested_for'); var deviceType = g_form.getValue('device_type'); // Fetch the display value for 'requested_for' using GlideAjax if needed var ga = new GlideAjax('UserDetails'); // Custom Script Include needed ga.addParam('sys_id', reqForSysId); ga.getXMLAnswer(function(response){ var reqFor = response.responseText; g_form.setValue('short_description_1', "Lost/Stolen " + deviceType + ' Reported By ' + reqFor); }); }

3. Custom Script Include for GlideAjax:

  • Create a Script Include named UserDetails to fetch the display value of the requested_for field:
    var UserDetails = Class.create(); UserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, { getDisplayValue: function() { var sysId = this.getParameter('sys_id'); var userGR = new GlideRecord('sys_user'); if (userGR.get(sysId)) { return userGR.getDisplayValue(); } return ''; } });
--------------------------------------------------------------------------------------------------------------------------


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/