I want my Planned Start date to select 3 business days from today in change Normal change request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 03:00 AM
I have a requirement on change request. For normal change when we select
****Urgency as Normal - Planned start date should auto populate 3 business working days from today's date but should show an error message when user is trying to change the planned start date.
Can some one guide me on the script requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 04:39 AM
@Community Alums I would like to inform you that I have added a wrong statement which has mis leaded you, when ever we create a normal change request it should auto populate the start date as 3 business days from today, and when user try's to modify it, it should show a error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 06:28 AM
Hi @Sanafelix1323 ,
No problem I modified my script you can take reference from below
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
alert('Check Urgency = ' + newValue)
if (newValue == 'normal' || newValue == 3) {
var ga = new GlideAjax('giveDate');
ga.addParam('sysparm_name', 'getDate');
ga.addParam('sysparm_startDate', g_form.getValue("start_date"));
ga.getXML(updateCampus);
}
function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('start_date', answer);
if(g_form.getValue('start_date')){
alert('You can not chnage the value of Start Dtae');
g_form.setReadOnly('start_date', true);
}
}
}
Script Include
var giveDate = Class.create();
giveDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDate: function(){
gs.log("Here", 'giveDate');
var dateThree = new GlideDateTime();
dateThree.addDays(3);
gs.log("threeDays = " + dateThree, 'giveDate');
return dateThree;
},
type: 'giveDate'
});
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-01-2024 06:30 AM
Hi @Sanafelix1323 ,
No problem I modified my script you can take reference from below
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } //Type appropriate comment here, and begin script below alert('Check Urgency = ' + newValue) if (newValue == 'normal' || newValue == 3) { var ga = new GlideAjax('giveDate'); ga.addParam('sysparm_name', 'getDate'); ga.addParam('sysparm_startDate', g_form.getValue("start_date")); ga.getXML(updateCampus); } function updateCampus(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); alert(answer); g_form.setValue('start_date', answer); if(g_form.getValue('start_date')){ alert('You can not chnage the value of Start Dtae'); g_form.setReadOnly('start_date', true); } } }
Script Include
var giveDate = Class.create(); giveDate.prototype = Object.extendsObject(AbstractAjaxProcessor, { getDate: function(){ gs.log("Here", 'giveDate'); var dateThree = new GlideDateTime(); dateThree.addDays(3); gs.log("threeDays = " + dateThree, 'giveDate'); return dateThree; }, type: 'giveDate' });
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-01-2024 07:32 AM
@Community Alums As you given i have tried it but their is again a new requirement we can modify the planned start date but it should not be less then the 3 business days if its less then 3 business days then it should show a error that the start date cannot be less then 3 business days from today . here the scenario is user should not be able to select the planned start date less then 3 business days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 04:23 AM - edited 05-01-2024 04:27 AM
Hi @Sanafelix1323 ,
There are multiple ways you can do this : Simplest is
1. As per your description i can suggest to set the default value of the start date field by calling a script include.
2. Create a UI policy to make the start_date field read only if the date field is not empty and change type is normal.
code example : Create a script include
var days = 3;
var creat= new GlideDateTime(current.sys_created_on); // created date
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days); //calculate duration of three days
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // Use the Existing 8-5 weekday scheues.
var updatedays = schedule.add(creat, dur);
return updatedays ;
I hope this helps...
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....