- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 10:31 AM
Hi all,
I've got a client script and script include that I'm using to set a date field based on the value of a variable on an asset record. I need to incorporate some code to set the value in the new field to match the user's date format to ensure there are no errors. Would using GlideDateTime and setDisplayValue be the way to go? my script below is setting the field correctly, but it's setting it in the system default format, I need it to set the value in the user's date format. thanks!
right now I have this for client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
return;
}
if (newValue == ''){
g_form.clearValue('computer_retirement_date');
return;
}
var ga = new GlideAjax('u_Computer_Requests_Ajax');
ga.addParam('sysparm_name', 'getRetirementDate');
ga.addParam('sysparm_ci', g_form.getValue('current_computer'));
ga.getXML(dateLookup); // Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)
}
// Callback function to process the response returned from the server
function dateLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('computer_retirement_date',answer);
}
and this is my script include:
getRetirementDate: function(){
var retVal; // Return value
var ci = this.getParameter('sysparm_ci');
var hardwareRec = new GlideRecord('alm_hardware');
hardwareRec.addQuery('ci',ci);
hardwareRec.query();
if(hardwareRec.next())
{
retVal = hardwareRec.retirement_date;
}
return retVal;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 10:54 AM
modify the script include as:
getRetirementDate: function(){
var gdt = new GlideDateTime();
var retVal ; // Return value
var ci = this.getParameter('sysparm_ci');
var hardwareRec = new GlideRecord('alm_hardware');
hardwareRec.addQuery('ci',ci);
hardwareRec.query();
if(hardwareRec.next())
{
gdt= hardwareRec.retirement_date;
retVal = gdt.getDisplayValue();
}
return retVal;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 11:06 AM
works perfectly, thanks Varun!