I want my Planned Start date to select 3 business days from today in change Normal change request.

Sanafelix1323
Tera Contributor

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.

11 REPLIES 11

Mark Manders
Mega Patron

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

Community Alums
Not applicable

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);
    }

}

SarthakKashyap_0-1714561205235.png

 

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'
});

SarthakKashyap_1-1714561249522.png

Result 

When Urgency is medium start date is 23

SarthakKashyap_2-1714561282144.png

 

When I change Urgency to Low it gives start dtae as 26 which is 3 days ahead 

SarthakKashyap_3-1714561355741.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards

Sarthak

 

update the code for business days !  


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Community Alums
Not applicable

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