- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 08:01 AM
Hi Guys,
What is the best way to fulfil below scenario:
On the Service Portal form, I have two fields (variables)
- req_received_date
- req_due_date
If I choose on the form while filling it out a date on 'req_received_date' field, for example, 1.12.22, I would like the 'req_due_date' field to be populated with a date 30 days ahead from 'req_received_date', which in this case would be 31.12.22? Can this be done by Catalog UI Policy?
I would very much appreciate your help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 08:40 AM
Sure.
onChange client script on first date field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearValue('date2');
return;
}
alert(newValue)
var ga = new GlideAjax('MyDateAjax');
ga.addParam('sysparm_name','mydatefunction');
ga.addParam('sysparm_date',newValue);
ga.getXML(cb);
// the callback function for returning the result from the server-side code
function cb(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('date2',answer);
}
}
Script Include
var MyDateAjax = Class.create();
MyDateAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
mydatefunction:function()
{
var dt=this.getParameter('sysparm_date');
var dtob=new GlideDateTime(dt);
dtob.addDaysUTC(30);
return dtob.getDate();
},
type: 'MyDateAjax'
});
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 08:08 AM
Hi,
You can use GlideAjax and onChange client script.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 08:15 AM
As I don't have any experience with GlideAjax, would you mind elaborating?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 08:40 AM
Sure.
onChange client script on first date field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearValue('date2');
return;
}
alert(newValue)
var ga = new GlideAjax('MyDateAjax');
ga.addParam('sysparm_name','mydatefunction');
ga.addParam('sysparm_date',newValue);
ga.getXML(cb);
// the callback function for returning the result from the server-side code
function cb(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('date2',answer);
}
}
Script Include
var MyDateAjax = Class.create();
MyDateAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
mydatefunction:function()
{
var dt=this.getParameter('sysparm_date');
var dtob=new GlideDateTime(dt);
dtob.addDaysUTC(30);
return dtob.getDate();
},
type: 'MyDateAjax'
});
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2022 08:41 AM
Change the variable names as per yours.
Thanks and Regards,
Saurabh Gupta