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

HIROSHI SATOH
Mega Sage

I hope this helps.

 

The issue you're experiencing is due to the difference in how the ServiceNow platform and Service Portal handle the retrieval of values for reference fields.

In the platform UI, g_form.getValue('device_type') returns the backend value (sys_id) of the reference field, while in the Service Portal, it often returns the display value (the label). This discrepancy can cause the issue where the backend name (sys_id) shows up in the short description field instead of the human-readable label.

To fix this, you need to ensure that you retrieve the display value of the reference field (device_type) in both the platform and the portal. Here’s an updated version of your script:

 

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

    g_form.getReference('device_type', function(deviceTypeRecord) {
        var deviceTypeValue = deviceTypeRecord.name || deviceTypeRecord.u_name; // Adjust based on your field name

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

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

 

 

Additionally

 

  1. UI Type Mismatch:

    • Check the Client Script's UI Type: Ensure the "UI Type" field of your client script is set to "All" or "Mobile/Service Portal" if it's intended for both platforms. If it's currently set to "Desktop," it won't execute in the Portal.
  2. GlideRecord Field Mapping Issues:

    • Verify GlideRecord Field Names: Double-check that the field names you're using in g_form.getValue('device_type') and g_form.getReference('requested_for') match the actual field names on your form. Case sensitivity matters, so ensure exact matches.

    • Utilize GlideRecord's getDisplayValue(): To ensure the client script always retrieves and sets the display value of the "Device Type" field (the user-friendly label) in both Portal and Platform, use getDisplayValue() within g_form.getReference('requested_for', function(requestedForRecord) { ... }):

       

 

var deviceTypeLabel = g_form.getValue('device_type').getDisplayValue();

 

  • Role-Based Access Control (RBAC) Restrictions:

    • Review User Roles and Permissions: If you're testing on the platform using a different user account than in the Portal, ensure that user has the necessary roles and permissions to access, read, and modify the relevant fields on the "Lost or Stolen Device" form. Insufficient permissions can lead to unexpected behavior.
  • Browser Caching and Inconsistencies:

    • Clear Browser Cache: Sometimes, cached data can interfere with script execution. Try clearing your browser cache (Ctrl+Shift+Delete or Cmd+Option+E) and reloading the platform to check if it resolves the issue.

Troubleshooting Steps:

  1. Check UI Type: Go to the client script record and verify the "UI Type" field. Set it to "All" or "Mobile/Service Portal" if needed.
  2. Review Field Names: Double-check all field names used in your script. Look for typos, case sensitivity mismatches, or custom field names instead of system fields.
  3. Inspect GlideRecord Usage: Implement getDisplayValue() to ensure you're working with display values (labels) consistently.
  4. Test with Different Users: If RBAC is suspected, try logging in with a user who has full access rights on the platform and see if the script works as expected.
  5. Clear Cache (if necessary): If other solutions don't work, consider clearing your browser cache as a last resort.

Additional Tips:

  • Enable Client Script Debugging: If the above steps don't resolve the issue, enable client script debugging in your ServiceNow instance to gain more insight into script execution and identify potential errors.
  • Consider Browser Compatibility (optional): In rare cases, the behavior might be caused by browser compatibility issues. Try testing with a different browser to see if that makes a difference.

By following these steps and considering the potential causes, you should be able to resolve the discrepancy between Portal and Platform behavior in your ServiceNow client script.

@Vaibhav127 @HIROSHI SATOH 

 

Showing undefined 

nameisnani_0-1724214891310.png

 

 

Platform side not at all working 

nameisnani_1-1724214993949.png

 

@HIROSHI SATOH 

 

As per your comments this is my updated script , please let me know what was mistake here 

nameisnani_2-1724215463838.png