Highlighted
Absent Member.
Absent Member.
544 views

Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

Hi Experts,

 

I need some help in writing the below requirement in Java Script

I have a Date Field say "Annual Date"

->I need to add the value as Current Date + one Year.

->Also I need to add Update Date + Year.

I tried to use tod() but I am facing the Issue on how to extract the Days.

Can some one kindly suggest.

Regards

-DK

0 Likes
1 Solution

Accepted Solutions
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

where is the save? 🙂

function Test() {
	
	var ticket = new SCFile("kmdocument");
	var rc = fRecord.doSelect("status=\"Triage\"");
	if ( rc == RC_SUCCESS ) {
		rcFirst = fRecord.getFirst();
		while (getLastRC() == RC_SUCCESS) {
			var d = new Date();
            d.setFullYear(d.getFullYear() +1);
            ticket.NextReviewDate = d;

			var rcSave = ticket.doSave();
			if ( rcSave == RC_SUCCESS ) {
				var rcNext = ticket.getNext();
 			}
		}
	}
}


View solution in original post

6 Replies
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution
		 var d = new Date();
		 d.setFullYear(d.getFullYear() +1); 
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

@Enzo_Potenza

Thanks for the reply.

Using your suggestion I created the below JS and added a Rule Set "Set FIeld" on "OnReturn" and "On SuccessfulReturn". But the script is not getting executed so no value is being set

 

function calc()
{

var d = new Date();
d.setFullYear(d.getFullYear() +1);
print(d);

record.NextReviewDate = d;

}

 

Kindly suggestion. Here the Field NextReviewDate is what I want

-Regards,

DK

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

you have to pass the record to your function

function calc(record)
{

var d = new Date();
d.setFullYear(d.getFullYear() +1);
print(d);

record.NextReviewDate = d;

}

can you post a screen of your RuleSet?

 

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

@Enzo_Potenza

Below is the complete Script I wrote

function Test()
{
var ticket = new SCFile("kmdocument");
var f = ticket.doSelect( "status=\"Triage\" ");
if ( f == RC_SUCCESS )
{
         do
         {
               var d = new Date();
               d.setFullYear(d.getFullYear() +1);

               ticket.NextReviewDate = d;

         }while (ticket.getNext() == RC_SUCCESS);

}


} Test();

Here now I am able to print the value that is stored in the field but that value is not visible on the form itself.

I am not able to see any Data in the field

Ruleset I am using in setField

Regards,

-DK

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

where is the save? 🙂

function Test() {
	
	var ticket = new SCFile("kmdocument");
	var rc = fRecord.doSelect("status=\"Triage\"");
	if ( rc == RC_SUCCESS ) {
		rcFirst = fRecord.getFirst();
		while (getLastRC() == RC_SUCCESS) {
			var d = new Date();
            d.setFullYear(d.getFullYear() +1);
            ticket.NextReviewDate = d;

			var rcSave = ticket.doSave();
			if ( rcSave == RC_SUCCESS ) {
				var rcNext = ticket.getNext();
 			}
		}
	}
}


View solution in original post

Highlighted
Absent Member.
Absent Member.

Re: Need to write a Java Script to Add Current Date/Update time + Year

Jump to solution

Thanku @Enzo_Potenza

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.