How to get the device age with the help of get warranty start date in the below variables a

Archana23
Tera Contributor

How to get the device age with the help of get warranty start date in the below variables and also have to validate that if the age is <=2186 days.

Please suggest.

Thanks in advance.

 

Archana23_0-1717520155560.png

 

1 ACCEPTED SOLUTION

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Archana23 

 

You can try the below code and it is working in my PDI:

 

client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var startdate=g_form.getValue('start_date');
   var date=new GlideAjax('GetManagerDetailsScript');
   date.addParam('sysparm_name','getdatedifference');
   date.addParam('sysparm_startdate',startdate);
   date.getXMLAnswer(callback);

   function callback(response){
	var answer= response;
	alert(answer);
	g_form.setValue('get_number_of_days_from_start_date',answer);
	if(answer<=2186){
		alert("in warranty") //do as per your requirement
	}
	else{
		alert("not in warranty");
	}
   }

Script Include:

var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getdatedifference: function() {
		var startvalue=this.getParameter('sysparm_startdate');
        var sgd1 = new GlideDate();
        sgd1.setValue(startvalue);
        var sgd2 = new GlideDate();
        sgd2.setValue(gs.getDate());

        var duration = GlideDate.subtract(sgd1, sgd2);
        var total=duration.getDayPart();
		return total;

    },






});

 

Thanks and Regards

Sai Venkatesh

View solution in original post

3 REPLIES 3

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Archana23 

 

You can try the below code and it is working in my PDI:

 

client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var startdate=g_form.getValue('start_date');
   var date=new GlideAjax('GetManagerDetailsScript');
   date.addParam('sysparm_name','getdatedifference');
   date.addParam('sysparm_startdate',startdate);
   date.getXMLAnswer(callback);

   function callback(response){
	var answer= response;
	alert(answer);
	g_form.setValue('get_number_of_days_from_start_date',answer);
	if(answer<=2186){
		alert("in warranty") //do as per your requirement
	}
	else{
		alert("not in warranty");
	}
   }

Script Include:

var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getdatedifference: function() {
		var startvalue=this.getParameter('sysparm_startdate');
        var sgd1 = new GlideDate();
        sgd1.setValue(startvalue);
        var sgd2 = new GlideDate();
        sgd2.setValue(gs.getDate());

        var duration = GlideDate.subtract(sgd1, sgd2);
        var total=duration.getDayPart();
		return total;

    },






});

 

Thanks and Regards

Sai Venkatesh

Archana23
Tera Contributor

Thank you so much @SAI VENKATESH .

It is working as expected.

Hi @Archana23 

Can you check the other question posted by you: https://www.servicenow.com/community/virtual-agent-forum/in-the-below-variable-i-need-to-show-the-in...

 

and can you confirm whether it is working or not. 

 

Thanks and regards

Sai Venkatesh