- 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-25-2022 02:03 AM
Still the same,
I am wondering if 'sysparm_date' is messing it up
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 02:17 AM
give me some time. I will get back.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 02:44 AM
Hi,
PFA screenshot from my PDI.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 02:53 AM - edited 11-25-2022 02:53 AM
Your PDI shows format yyyy-mm-dd,
if you look at my screenshot is dd-mm-yyyy,
I'm struggling to figure out what might be wrong, But it looks like in Script Include somewhere at this stage:
it gets messed up. I am wondering if I could format it correctly after this line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 02:57 AM
Hi,
Please refer below API doc link
GlideDateTime | ServiceNow Developers
Thanks and Regards,
Saurabh Gupta
