Date Format Change to "dd-mm-yyyy" for catalog item variable

Rajarshi1
Tera Expert

Hi,

I have a requirement to populate the value of one catalog variable in "DD-MM-YYYY" format. This will happen based on a change in another catalog variable which is in "YYYY-MM-DD" format. I have written a catalog client script and a script include but the date format is not changing. It will be of great help if you suggest something on this. Am I missing something?

Client Script

find_real_file.png

Script Include

find_real_file.png

 

Output

find_real_file.png

Thanks,

Rajarshi

1 ACCEPTED SOLUTION

Try this-

After line 9

var formatdate= day.getByFormat("dd-MM-yyyy");

return formatdate;

 

View solution in original post

14 REPLIES 14

Hi Rajashri,

Could you mark my answer correct as I have invested my time in this and provided you the solution and code changes for your requirement.

Definitely

I tried this but it is not working

 

Script include

var date1 = Class.create();
date1.prototype = object.extendsObject(AbstractAjaxProcessor,{

date:function()
{
var pg = this.getParameter('sysparm_abc');
var day = new GlideDate();
day.setDisplayValue(pg);
var formatdate= day.getByFormat("MM/dd/yyyy");
return formatdate;

}

});

 

 

 

CLient script

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cdt = g_form.getValue('requested_date');
var ga = new GlideAjax('date1');
ga.addParam('sysparm_name', 'date');
ga.addParam('sysparm_abc',cdt);
ga.getXML(testing);

function testing(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
var ag = ans.toString();
alert(ag);
g_form.setValue('priority',ag);
}
//Type appropriate comment here, and begin script below

}

 

Can you let me know why?

Swapnil Soni1
Giga Guru

Hi,

In addition to above, check this thread

https://community.servicenow.com/community?id=community_question&sys_id=161ac769db5cdbc01dcaf3231f96...

 

Let me know if this helps.

Thanks

kamal11
Giga Expert

I tried this but it is not working

 

Script include

var date1 = Class.create();
date1.prototype = object.extendsObject(AbstractAjaxProcessor,{

date:function()
{
var pg = this.getParameter('sysparm_abc');
var day = new GlideDate();
day.setDisplayValue(pg);
var formatdate= day.getByFormat("MM/dd/yyyy");
return formatdate;

}

});

 

 

 

CLient script

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cdt = g_form.getValue('requested_date');
var ga = new GlideAjax('date1');
ga.addParam('sysparm_name', 'date');
ga.addParam('sysparm_abc',cdt);
ga.getXML(testing);

function testing(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
var ag = ans.toString();
alert(ag);
g_form.setValue('priority',ag);
}
//Type appropriate comment here, and begin script below

}

 

Can you let me know why?