Newvalue and oldvalue in onsubmit Client script

Anburaj
Giga Contributor

I have requirement like in change request , while change manager is approving the change request

if proposed start date or proposed end date is changed that time, i need to throw a error message.

I need to do this scenario in onsubmit client script.

I got the proper query, but these proposed date change am having the problem.

using get value i got the proposed start date or proposed end date in a variable.

But in need to set new value of proposed start date != old value of proposed start date

or newvalue of proposed end date != old value of proposed end date.

How to achieve this in client script onsubmit?

Please help.

1 ACCEPTED SOLUTION

PriyaRanji
Tera Guru

Hi Anburaj,



Good Day!



function onSubmit() {


var approver = g_form.getValue('approver');


if(approver != ''){
validateTravelEndDate();


return false;
}


else{


return true;


}


}



//Helper function which calls a AJAX script include called "ClientDateTimeUtils" which gives the response in a callback where i am deciding whether to submit the form or not based on the status of days result.

function validateTravelEndDate() {
  var startDate = g_form.getValue('proposed_start_date'); //First Date/Time field
  var endDate = g_form.getValue('proposed_end_date'); //Second Date/Time field
  var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.

  var ajax = new GlideAjax('ClientDateTimeUtils'); // This is the script include which can be used for date validation.
  ajax.addParam('sysparm_name', 'getDateTimeDiff');
  ajax.addParam('sysparm_fdt', startDate);
  ajax.addParam('sysparm_sdt', endDate);
  ajax.addParam('sysparm_difftype', dttype);
  ajax.getXML(checkDateDiff);
}

// callback function where deciding to go ahead or not with form submission.
function checkDateDiff(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  if (answer <= 0) {
  alert("Proposed End date must be after Proposed Start date.");
g_form.setValue('proposed_end_date', '');
  g_form.showFieldMsg('proposed_end_date', 'Please provide a future date', 'error');
  return false;
} else {
  g_form.submit(); // This has some issue as it's going in the infinite loop and if we just return true/false from here as it's asynchronous call , it's not handled by the onSubmit function
  }
}



PS: hit correct/helpful....if it helps




Thanks,


Priyanka R


View solution in original post

16 REPLIES 16

I created as per your code..


but still i have problem...



function date(){




  var startDate = g_form.getValue('start_date'); //First Date/Time field


  var endDate = g_form.getValue('end_date'); //Second Date/Time field


  var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.


  var ajax = new GlideAjax('ClientDateTimeUtils'); // This is the script include which can be used for date validation.


  ajax.addParam('sysparm_name', 'getDateTimeDiff');


  ajax.addParam('sysparm_fdt',startDate);


  ajax.addParam('sysparm_sdt',endDate);


  ajax.addParam('sysparm_difftype', dttype)


  ajax.getXML(checkDateDiff);




}


function checkDateDiff(response) {


var str_changeType = g_form.getValue('type');


var conflict = g_form.getValue('conflict_status');


var actionName = g_form.getActionName();




  var answer = response.responseXML.documentElement.getAttribute("answer");


  if (answer <= 0) {



if(actionName == 'approve_button'){


if(str_changeType == 'Normal'|| str_changeType == 'Expedited'){


if(conflict == 'Conflict'){


alert('Your change request has triggered a conflict condition');


if (answer == false){


return false;


}


else{


return true;


}


}


}



could you please check..


Hi Anbu,



Good Evening!



I have given the sample code, please do modify based on your field and values that you are selecting.



Let me know it is working or not with your changes.



Thanks,


Priyanka R


Hi,



Can you please refer the below link for your reference. Hope it will helps you out!



Client Script Date/Time Functions



Please hit it as Correct/Helpful/Like based on the impact.



Thanks,


Priyanka R


all is corect except this ajax.addParam('sysparm_name', 'getOutageDateTimeDiff');


i changed this one and also the code according and its works.



Thanks.


Hi Anbu,



Good Day



Wow! That's Great!



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



Thanks,


Priyanka R