Create UI action button to extend the current KB record for 1 year

Shree22
Tera Contributor

Please help me  this is my script for extend button, click on the button then directly open KB_knowledge list view page. please help me find the solution.

Shree22_0-1691398507747.png

 

1 ACCEPTED SOLUTION

Hi,

Create like below:

Screenshot 2023-08-07 at 4.20.03 PM.png

 

Below is the script:

extendByYear(current);
function extendByYear(current){
	var nextDate = new GlideDateTime(current.valid_to);
	nextDate.addYearsUTC(1);
	current.valid_to = nextDate.getDate();
	current.update();
	action.setRedirectURL(current);
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

8 REPLIES 8

Glad to know your issue is resolve. Happy Learning 😊 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hello @Anil Lande 

Can you please explain me the code

Hi @shaik23 

 

Please check inline comments explaining each line.

 

extendByYear(current);  // calling the function defined below 
function extendByYear(current){  // function defination
	var nextDate = new GlideDateTime(current.valid_to);  // crate variable (object) of type GlideDateTime and initialize it with value selected in valid_to field
	nextDate.addYearsUTC(1);  // addYearsUTC is methode of GlideDateTime class, it add one year to the Date set previously
	current.valid_to = nextDate.getDate(); // set the updated date to the field valid_to, getDate() returns date part form Date and Time
	current.update(); // update the current record
	action.setRedirectURL(current);  // redirect to same form after saving record.
}

 

You can learn more about GlideDateTime API on below official documentation page.

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_APIRef#r_ScopedG...

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks for the reply very helpful