2.2.difference behaviour b/w platform and in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 07:26 PM
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
Platform view
The Result should come like this
In both Platform and in portal .
can anyone please help me here , what changes should i need to do in my script .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:19 PM
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);
});
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:25 PM
Additionally
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.
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:
- 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.
- 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.
- Inspect GlideRecord Usage: Implement getDisplayValue() to ensure you're working with display values (labels) consistently.
- 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.
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 09:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 09:44 PM
As per your comments this is my updated script , please let me know what was mistake here