The CreatorCon Call for Content is officially open! Get started here.

How to set incident state is "WIP" automatically

akin9
Tera Contributor

Hello expets

We have requirment.

 

We have a field is  Due date.  If below conditions are met field will be visible. or else Hide.

akin9_0-1668519746116.png

 

Requirement is 

Incident should switch back to WIP as soon as the set date/time is reached.

Please support to achieve this

16 REPLIES 16

@akin9 

Glad to help.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

Thanks for motivating me!

I tried with below code but unfortunately not working properly.

function onLoad() {
//Type appropriate comment here, and begin script below


var postpone = g_form.getValue('u_postpone_schedule');

var ajax = new GlideAjax('date/timeToday');

ajax.addParam('sysparm_name', 'date/timeToday');

ajax.addParam('sysparm_postpone', postpone);

ajax.getXMLWait();

var answer = ajax.getAnswer();

g_form.setValue('state', 2);

}

 

Issue is normally state is in on hold.

akin9_0-1668578713452.png

But after opening only the incident it is changed to InProgress

akin9_1-1668578836009.png

 

But my requirment is if Postpone date is reached then incident should be switch to inprogress automatically.

or else we can achieve this by any Before/after BR?

Plesae help me on this , 

Thank you.

@akin9 

you can use Display business rule on incident table and check this

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var nowTime = new GlideDateTime();
	var postpone = new GlideDateTime(current.u_postpone_schedule);

	if(nowTime.getNumericValue() == postpone.getNumericValue())
		g_scratchpad.isDateReached = 'true';
	else
		g_scratchpad.isDateReached = 'false';

})(current, previous);

onLoad client script

function onLoad(){

	if(g_scratchpad.isDateReached == 'true')
		g_form.setValue('state', 2);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Thank you for your Quick reply ,

i tried above code but unfortunately not working. Please correct me if any wrong.

 

akin9_2-1668582285908.png

 

 

akin9_0-1668582178918.pngakin9_1-1668582199360.png

akin9_3-1668582364658.png

 

@akin9 

what's your current time and what's the time in that field?

date is same but time should also be same -> but it would be very difficult since time has seconds also in it

try this

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var nowTime = new GlideDateTime();
	var postpone = new GlideDateTime();
        postpone.setDisplayValue(current.u_postpone_schedule):

	if(nowTime.getNumericValue() == postpone.getNumericValue())
		g_scratchpad.isDateReached = 'true';
	else
		g_scratchpad.isDateReached = 'false';

})(current, previous);
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader