Client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2024 03:58 AM
I have a catalog item having 3 variables all are lookup selectbox and having refference for all 3 variable as cmdb_ci_server in which owner and os field is read only. If I select owner name it should populate me both Owner and OS . When I try my client script it is working but in service portal it is not working.
My client script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === ") {
return;
}
// Call the Script Include using GlideAjax
var ga = new GlideAjax("GetServerDetails'); // Name of the Script Include ga.addParam('sysparm_name', 'getDetails"); // Function name in the Script Include ga.addParam("sysparm_serverName', newValue); // Pass the newValue (serverName)
ga.getXML.Answer(function(response) {
var serverDetails = JSON.parse(response); // Parse the JSON response
if (serverDetails) {
form.setValue(owner', serverDetails.owner):
g_form.setValue('os', serverDetails.os);
}
});
}
Script include -
var GetServerDetails = Class.create():
GetServerDetails.prototype = Object.extend(new AbstractAjaxProcessor(). {
getDetails: function() {
var serverName = this.getParameter('sysparm_serverName'); // Fetch the parameter from the client script
var serverDetails = {
OS:",
owner:"
}
// Query the amdb_ci_server table
var server = new GlideRecord('cmdb_ci_server');
server.addQuery('name', serverName);
server.query():
if (server.next()) {
// Fetch OS and owner details
serverDetails.os = server.os.toString():
serverDetails.owner = server.owned_by.toString(): // Assuming "owned_by" is the field name for the owner
}
retum JSON.stringify(serverDetails); // Return JSON string
}
});
When I run this in catalog item ui ie try it it works but in service portal it doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2024 05:20 AM
Did you check if the UI Type field has dropdown value Both on catalog client script record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2024 07:13 AM
Did you check the UI type - ALL for your catalog client script?
what came in alert for the ajax response in portal?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2024 09:52 PM
It is working in service portal now I have a extra condition after the above condition if I select submit button it should generate me a report with 3 columns ie Server Name OS and Owner
So how to customise the submit button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2024 10:33 PM
It seems like you've selected UI Type as "All" and set the type of Owner_name and OS as reference. However, you're only passing the name and not the entire reference record, which is why it's not working on the portal.
To verify this, try submitting the catalog form. If you don't see the Owner_name and OS data in the RITM form, you'll need to update your script. You can either send the entire record via Script Include or change the type of the variables.