- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 09:13 AM
Hello All,
I'm trying to write a simple message in a single line text variable based on if a record is true or false. I'm using this within an onLoad catalog client script. I know I'm missing something very basic and likely writing this all wrong. Any assistance is greatly appreciated.
function onLoad() {
//Type appropriate comment here, and begin script below
//set name of notification
var notifname = 'b6ff52e947513d9086861192e36d43eb';
//look up notification based on notif name
var notifon = new GlideRecord('sysevent_email_action');
notifon.addQuery ('sys_id' , notifname);
notifon.addQuery ('active' , 'true');
notifon.query;
var notifoff = new GlideRecord('sysevent_email_action');
notifoff.addQuery ('sys_id' , notifname);
notifoff.addQuery ('active' , 'false');
notifoff.query;
if(notifon.next()) {
g_form.setValue('is_short_staffed_message_on', "Short Staffed msg is ON");
}
else if (notifoff.next()) {
g_form.setValue('is_short_staffed_message_on', "Short Staffed msg is OFF");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 09:39 AM - edited 04-29-2024 09:50 AM
Hi @BR Admin
The problem here is, you cannot do server side operation in client script. You should use GlideAjax for this
Please use this
Create a client callable script include and use the following script:
getNotificationFlag: function() {
var notifname = "b6ff52e947513d9086861192e36d43eb";
var notifon = new GlideRecord('sysevent_email_action');
notifon.addQuery('sys_id', notifname);
notifon.addQuery('active', 'true');
notifon.query();
if(notifon.next()){
return "true";
}
else
return "false";
},
Modify your client script like this
function onLoad() {
var ga = new GlideAjax('TestAjaxScriptInclude'); //Please use your script include
ga.addParam('sysparm_name', 'getNotificationFlag');
ga.getXMLAnswer(function(response) {
if (response == "true") {
g_form.setValue('is_short_staffed_message_on', "Short Staffed msg is ON");
} else if(response == "false")
g_form.setValue('is_short_staffed_message_on', "Short Staffed msg is OFF");
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 09:39 AM - edited 04-29-2024 09:50 AM
Hi @BR Admin
The problem here is, you cannot do server side operation in client script. You should use GlideAjax for this
Please use this
Create a client callable script include and use the following script:
getNotificationFlag: function() {
var notifname = "b6ff52e947513d9086861192e36d43eb";
var notifon = new GlideRecord('sysevent_email_action');
notifon.addQuery('sys_id', notifname);
notifon.addQuery('active', 'true');
notifon.query();
if(notifon.next()){
return "true";
}
else
return "false";
},
Modify your client script like this
function onLoad() {
var ga = new GlideAjax('TestAjaxScriptInclude'); //Please use your script include
ga.addParam('sysparm_name', 'getNotificationFlag');
ga.getXMLAnswer(function(response) {
if (response == "true") {
g_form.setValue('is_short_staffed_message_on', "Short Staffed msg is ON");
} else if(response == "false")
g_form.setValue('is_short_staffed_message_on', "Short Staffed msg is OFF");
});
}