- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 08:17 AM
In a form, a time field "start time", needs to be populated according to the start time from a schedule entry chosen by the user. e.g.: The user selects the "Morning" schedule which has 8 am as the start time and this value is displayed in the "start time" field; If the user chooses a different schedule, "Afternoon" that has 1 pm as the start time, it should change accordingly.
I've created a Client Script and a Script Include but still unable to retrieve the start time value.
Here is the code so far:
Script Include (set as Client callable):
var GetScheduleStartTime = Class.create();
GetScheduleStartTime.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
initialize: function() {
},
getStartTime: function() {
var scheduleId = this.getParameter('sysparm_schedule');
var startTime = ''; // Initialize the start time variable
// Fetch the start time from the selected schedule using GlideRecord
var scheduleGR = new GlideRecord('cmn_schedule');
scheduleGR.query();
if (scheduleGR.get(scheduleId)) {
startTime = scheduleGR.getValue('start_date_time');
}
return startTime;
},
type: 'GetScheduleStartTime'
});
Client Script (onChange):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var scheduleField = g_form.getValue('schedule');
if (!scheduleField || newValue === oldValue) {
return;
}
var ga = new GlideAjax('GetScheduleStartTime');
ga.addParam('sysparm_name', 'getStartTime');
ga.addParam('sysparm_schedule', scheduleField);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer) {
g_form.setValue('start_time', answer);
}
});
}
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2023 01:29 AM
Hi @Samaksh Wani
Thanks for your help, unfortunately, I won't be able to use :
ga.getXMLWait();
since I am working on a scoped application, access is not available.
I would need a different approach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 11:11 AM
Hello @ICaTonyBalde
Make this changes in Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var scheduleField = g_form.getValue('schedule');
if (!scheduleField || newValue === oldValue) {
return;
}
var ga = new GlideAjax('GetScheduleStartTime');
ga.addParam('sysparm_name', 'getStartTime');
ga.addParam('sysparm_schedule', scheduleField);
ga.getXMLWait();
var answer = ga.getAnswer();
if (answer) {
g_form.setValue('start_time', answer);
}
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2023 01:29 AM
Hi @Samaksh Wani
Thanks for your help, unfortunately, I won't be able to use :
ga.getXMLWait();
since I am working on a scoped application, access is not available.
I would need a different approach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2023 02:18 AM