calculate the days when option one weel or one month is selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 09:26 PM
Hi All,
Having a requirement that, on a catalog form we have a multiple option selection field.
contains options 1 day, one week, one month, and six months.
i created a date field which is hiding in the form view. here i need to set the value in this date field based on the option selected in the multiple choice. if one week i selected then in the date filed calculate from the requested date to one week. vise versa same for the one month also.
Need any suggestions.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 12:08 AM
Hi @Community Alums ,
I tried your problem in my PDI and it works for me
I created 2 variable One contains select box like 1 Day, 1 Week, 1 Month and another contains the date
I created onSubmit clint script and added below code
function onSubmit() {
//Type appropriate comment here, and begin script below
alert(g_form.getValue("select_range"));
var ga = new GlideAjax('updateDate');
ga.addParam('sysparm_name', 'updateDateFunction');
ga.addParam('sysparm_dateRange', g_form.getValue("select_range"));
ga.addParam('sysparm_dateValue', g_form.getValue("show_date"));
ga.getXML(updateCampus);
function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('show_date', answer);
}
}
Script Include
var updateDate = Class.create();
updateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateDateFunction: function() {
var dateRange = this.getParameter('sysparm_dateRange');
var dateShow = this.getParameter('sysparm_dateValue');
gs.log('DateRange = ' + dateRange + " dateShow = " + dateShow);
if (dateRange == 'one_day') {
dateShow.addDaysUTC(1);
gs.log('One day ' + dateShow.getValue());
return dateShow;
}
if (dateRange == 'one_week') {
dateShow.addDaysUTC(7);
gs.log('RFS created ' + dateShow.getValue());
return dateShow;
}
if (dateRange == 'one_month') {
dateShow.addDaysUTC(30);
gs.log('One moth ' + dateShow.getValue());
return dateShow;
}
},
type: 'updateDate'
});
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 03:54 AM
Hi @Community Alums
Thanks for the swift response.
I tried the above suggestion its not working for me it returning the null value.
And one more here i have a variable type is multiple choice not as the select box(drop down)
even i tried with the select box also its not working.
Client script:
And the script include is
var updateDate = Class.create();
updateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateDateFunction: function() {
var dateRange = this.getParameter('sysparm_dateRange');
var dateShow = this.getParameter('sysparm_dateValue');
gs.log('DateRange = ' + dateRange + " dateShow = " + dateShow);
if (dateRange == 'one_day') {
dateShow.addDaysUTC(1);
gs.log('One day ' + dateShow.getValue());
return dateShow;
}
if (dateRange == 'one_week') {
dateShow.addDaysUTC(7);
gs.log('RFS created ' + dateShow.getValue());
return dateShow;
}
if (dateRange == 'one_month') {
dateShow.addDaysUTC(30);
gs.log('One moth ' + dateShow.getValue());
return dateShow;
}
},
type: 'updateDate'
});
Even in the logs also getting empty value.
Any suggestions.