I have a requirement with the selecting of computer name , we need to display the warranty end date

Archana23
Tera Contributor

I have a requirement with the selecting of computer name , we need to display the warranty end date and in warranty left variable we need to display how much days still left for warranty exipration.

Example-SE-5CD2287V8T, Warranty Expired in 2023, The Warranty left days should show in Negative i.e -425 days. If value is in Positive, request should not move further since Warranty is still left for the device.

 

Archana23_0-1722594096699.png

Archana23_1-1722594156435.png

 

 

4 REPLIES 4

Priyanka_786
Tera Guru
Tera Guru

@Archana23 : Understanding your requirement, breaking down in below steps.

1. I believe warranty end date is coming from computer table , if yes then you can use  "Auto populate" tab on variable of Warranty end date where you can dot walk end date from computer table field which is reference type.

2.  To calculate Warrantly left(in days) variable you need to write onLoad client script call script include where you write logic. Refer this thread for script. https://www.servicenow.com/community/developer-forum/trying-to-calculate-days-remaining/m-p/1681241/...

3. For the validation of If value is in Positive, request should not move further since Warranty is still left for the device. you need to write onSubmit client script.

function onSubmit() {
   var inputField = g_form.getValue('variable name'); // replace field_name with the name of the field warrantly left
   var regex = /^[0-9]+$/;
   if (regex.test(inputField)) {
      gs.addErrorMessage("Request cannot submitted");// display an error message if the input is invalid
      return false; // prevent the form from being submitted
   }
   return true; // allow the form to be submitted if the input is valid
}

Hope it helps.

Please mark my response as helpful/accepted if it helps.

Regards,

Priyanka Salunke

HrishabhKumar
Kilo Sage

Hi @Archana23 ,

Let me know if I understood your requirement correctly.

Once you select the computer(which is a reference field), the warranty expired date is auto populated(i.e the warranty expiration date, present on the computer record).

And Warranty Left field is also auto populated by +ve or _ve based on the expiration date).

 

Let me know if I got it right, If yes then I can provide you a client script that could fulfil you requirement.

Yes it's correct

Hi @Archana23 ,

Please refer to the solution proposed by @Priyanka_786 .

It should help you!