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 03:17 AM
Is this on the backend or on the portal? Do you want to allow people to change the start date, or just show a message? Do you need to prevent the creation of the change if it's shorter than 3 days, or just a message? Is the message also to be shown if the date is set to further in the future?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 04:02 AM
Hi @Sanafelix1323 ,
I tried your problem in my PDI and it works for me please refer below steps
I created onChange Client script of Urgency variable and added below code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
alert('Check Urgency')
if (newValue == '3' || 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);
}
}
I created Script include which if client callable and added below code
var giveDate = Class.create();
giveDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDate: function(){
gs.log("Here", 'giveDate');
var sDate = this.getParameter('sysparm_startDate');
var dateThree = new GlideDateTime(sDate);
dateThree.addDays(3);
gs.log("threeDays = " + dateThree, 'giveDate');
return dateThree;
},
type: 'giveDate'
});
Result
When Urgency is medium start date is 23
When I change Urgency to Low it gives start dtae as 26 which is 3 days ahead
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 04:28 AM
update the code for business days !
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 04:32 AM - edited 05-01-2024 04:37 AM
Hi @Sohail Khilji and @Sanafelix1323 ,
Please check this link for business days
https://www.servicenow.com/community/developer-articles/add-business-days/ta-p/2324391
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak