When user click the Resolve button, valid to field value needs to be updated automatically

maheshch18
Tera Contributor

Hi team,

 

When the user clicks the Resolve button, the "valid to" field value needs to be updated automatically.

 

re-publishing that and the revised "valid to" date should be for another 6 months time (i.e. 180 days from the date of re-publishing the KBA).

 

Regards,

Mahesh.

3 REPLIES 3

Aman Kumar S
Kilo Patron

Hi @maheshch18 ,

Share more details about your requirement

Best Regards
Aman Kumar

Hi Aman,

 

When the user clicks the republish button and valid date needs to be updated automatically.

 

for example:

 

Valid date: 2023-08-01

 

Needs to be updated as valid to 2024-02-17 (180 days from the date of re-publishing the knowledge article).

SwarnadeepNandy
Mega Sage

Hello @maheshch18,

 

To update the “valid to” field value automatically when the user clicks the Resolve button, you will need to create a business rule that runs on the kb_knowledge table when the state changes to Resolved. The business rule should calculate the new date by adding 180 days to the current date, and then set the “valid to” field value to that date. You can use the GlideDateTime API to manipulate dates in ServiceNow.

 

Here is an example of a business rule script that you can use or modify for your purpose:

// Get the current record
var gr = current;

// Check if the state is Resolved
if (gr.state == 'Resolved') {
  // Get the current date
  var gdt = new GlideDateTime();
  gdt.setValue(gr.sys_updated_on);

  // Add 180 days to the current date
  gdt.addDays(180);

  // Set the "valid to" field value to the new date
  gr.valid_to = gdt;
}

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy