- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 04:53 AM
I have location filed in form.When I am changing the location field it should check if that location has group in cmn_location table.if it has a group then I should get popup message like do not submit request.How to do this.
I tried this but it is not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 04:57 AM
Please below updated code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getDisplayValue('u_location');
var gr = new GlideRecord('cmn_location');
gr.addQuery('full_name', location);
gr.query();
if (gr.next()) {
var Group = gr.group; // Corrected variable name
if (Group !== '') { // Check if group is not empty
alert('Selected Location has group.'); // Corrected alert message
}
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 05:04 AM
Hi @Shahida07
Using Glide Record in the client script is not a good practice, try using a Script Include and then calling a GA in your client script:
var LocationUtils = Class.create();
LocationUtils.prototype = {
initialize: function() {
},
hasGroup: function(location) {
var gr = new GlideRecord('cmn_location');
gr.addQuery('full_name', location);
gr.query();
return gr.next() && gr.group != null;
},
type: 'LocationUtils'
};
--
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var location = g_form.getValue('u_location');
var ga = new GlideAjax('LocationUtils');
ga.addParam('sysparm_name', 'hasGroup');
ga.addParam('sysparm_location', location);
ga.getXML(onSuccess);
function onSuccess(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
g_form.showFieldMsg('u_location', 'Selected location has group', 'error');
}
}
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 05:18 AM
It is not working.I tried this.