The CreatorCon Call for Content is officially open! Get started here.

how to set due date 2 hours from current date/time using client script

jahnavi chanda
Tera Contributor

Hi All,

I have a requirement, based on the type selection I need to auto populate due date 2 hours from current date/time using client script How to do it please any one help me.

Thanks in advance!

15 REPLIES 15

@jahnavi chanda 

so what script did you use? please share that

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

jahnavi chanda
Tera Contributor
This is the client script I am using, by using this script I am getting Thu Apr 13 2023 13:05:12 GMT+0530 (India Standard Time) . But I want 13/04/2023 01:05:12 this format. Someone Please help on this. 
   
var ga = new GlideAjax('AutoFill');
    ga.addParam('sysparm_name', 'taskType');
    ga.addParam('sysparm_type', g_form.getValue("u_type"));
    ga.getXML(callBack);
 
    function callBack(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
                var now = new Date();
var dueDate = new Date(now.getTime() + (2 * 60 * 60 * 1000));
if (g_form.getValue('u_type') == 16) {
 g_form.setValue('due_date', dueDate);
        }
}
 
Script include:

var AutoFill = Class.create();
AutoFill.prototype = {
initialize: function() {},

taskType: function() {
var type = this.getParameter('sysparm_type');
var myQuery = "u_type=" + type;
var myCode = new GlideRecord("sn_customerservice_task");
myCode.addEncodedQuery(myQuery);
myCode.query();
if (myCode.next()) {
return true;
} else {
return false;
}
},

type: 'AutoFill'
};

@jahnavi chanda 

why are you using Ajax here? you are just returning true/false from script include and not using the answer variable as well in your callback method

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@jahnavi chanda 

any update to this thread?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @jahnavi chanda 

This code is not correct you have mixed two things in here and you are using old code which i share with you.