Set a Catalog Item variable on Task Closure

vivek72
Tera Guru

Hi,

 

I have catalog item with 2 variables i.e. Start Date and End Date .

From this item, I have 2 reqs. as below:

1. New variable var1 (radio button) should be populated as success if Task creation date is 5 days before Start Date else failure.

2. New Variable var2 should be populated as success if  var1 is success and Task closed date is before End Date else failure.

 

please let me know how shall we implement this if it's feasible to do .

 

thanks,

Vivek

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @vivek72 you can create 2 client scripts on request table like below

1. Create a on Load client script to set start date for success/failure

  var getStartDate = new Date(g_form.getValue('variables.start_date'));// make sure variable names are correct
  alert(getStartDate);
var todayDate = new Date();
var timeDiff = Math.abs(todayDate.getTime() - getStartDate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
alert(diffDays);
if(diffDays <= 5)
{
    alert("less than 5 days");
    g_form.setValue("variables.variablename",'success'); //
}
else
{
    alert('more than 5 days');
    g_form.setValue("variables.variablename",'failure'); //
}
 
2. create onSubmit client script to set end date
  var getEndDate = new Date(g_form.getValue('variables.end_date')).getTime();
  alert(getEndDate);
var closedDate = new Date(g_form.getValue('closed_at')).getTime(); // closed field captures closure time on req
 alert(closedDate);
if(closedDate <= getEndDate){

alert("closed date is less than get date");
}
else{
    alert("closed date is greater than get date");
}
 
 
Regards
Harish

View solution in original post

5 REPLIES 5

Harish KM
Kilo Patron
Kilo Patron

Hi @vivek72 you can create 2 client scripts on request table like below

1. Create a on Load client script to set start date for success/failure

  var getStartDate = new Date(g_form.getValue('variables.start_date'));// make sure variable names are correct
  alert(getStartDate);
var todayDate = new Date();
var timeDiff = Math.abs(todayDate.getTime() - getStartDate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
alert(diffDays);
if(diffDays <= 5)
{
    alert("less than 5 days");
    g_form.setValue("variables.variablename",'success'); //
}
else
{
    alert('more than 5 days');
    g_form.setValue("variables.variablename",'failure'); //
}
 
2. create onSubmit client script to set end date
  var getEndDate = new Date(g_form.getValue('variables.end_date')).getTime();
  alert(getEndDate);
var closedDate = new Date(g_form.getValue('closed_at')).getTime(); // closed field captures closure time on req
 alert(closedDate);
if(closedDate <= getEndDate){

alert("closed date is less than get date");
}
else{
    alert("closed date is greater than get date");
}
 
 
Regards
Harish

Hi @Harish KM  : Thanks for replying.

1st script is clear to me and will try but I have a doubt on second script, 'closed at' is not available till task is closed.

How onSubmit script will work here ?

Hi @vivek72  good point then change it to onLoad.

Regards
Harish

Hi @Harish KM : ok, so when user will close task manually , this 2nd onLoad catalog client script will run and set the catalog variable var2 as success?

Will give it a try, thank you so much for guiding and suggest a starting point here 🙂