- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 05:18 AM
I recently implemented the populating of the variables from a URL with help from Michael but for some reason the new expiration date value is not storing what is passed in but the other two fields are. It is defaulting to today's date? From what I have read online, the date fields in ServiceNow can be quite picky. Below is my dilemma:
Here is the URL that I am testing with and is currently pulling the values onto the form (screenshot below).
I do not touch any of the fields they are what I want so I click submit. When I do, here is the RITM record:
Here is my code from the Catalog Client Script that is running. It populates all 3 variables but the date is not sticking it is defaulting to the current date? BUT if I update the pre-populated date with a new date value, it stores it then??
function onLoad() {
var User = getParameterValue('sysparm_requestedfor');
var usr = new GlideAjax('FindRequestedFor');
usr.addParam('sysparm_name', 'getRequestedFor');
usr.addParam('sysparm_user', User);
usr.getXML(getUserParse);
function getUserParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(User != undefined || User != '') g_form.setValue('requested_for', answer);
}
var Date = getParameterValue('sysparm_expdte');
var comments = getParameterValue('sysparm_comments');
if(Date != undefined || Date != '') g_form.setValue('new_expiration_date', Date);
if(comments != undefined || comments != '') g_form.setValue('sc_all_items_notes', comments);
}
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
Any assistance would be greatly appreciated. This last thing is preventing me from migrating my code to Production.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 05:33 AM
Hi,
That's because the date format you are receiving in the url is
20190801
but the date field accepts format as 2019-09-01 i.e. YYYY-MM-DD
better to send the code in the above format and then set value
var Date = getParameterValue('sysparm_expdte');
if you can't change the date format while sending to the URL then have this script to manipulate the date
var Date = getParameterValue('sysparm_expdte');
var year = Date.substring(0,4);
var month = Date.substring(4,6);
var day = Date.substring(6,str.length);
var updatedDate = year + '-' + month + '-' + day;
g_form.setValue('new_expiration_date', updatedDate);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 05:33 AM
Hi,
That's because the date format you are receiving in the url is
20190801
but the date field accepts format as 2019-09-01 i.e. YYYY-MM-DD
better to send the code in the above format and then set value
var Date = getParameterValue('sysparm_expdte');
if you can't change the date format while sending to the URL then have this script to manipulate the date
var Date = getParameterValue('sysparm_expdte');
var year = Date.substring(0,4);
var month = Date.substring(4,6);
var day = Date.substring(6,str.length);
var updatedDate = year + '-' + month + '-' + day;
g_form.setValue('new_expiration_date', updatedDate);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 12:04 PM
Thank you. I tried this and these behavior occurred. Thank you for the quick response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2019 10:17 AM
Actually, I had an additional line of code further down that was over writing your suggestion. When I commented that out, it worked!!!!!! Thank you!!! it was the format that it was being 'particular' with when saving the record. Thank you again!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 05:35 AM
Hi Colleen,
It sounds like you need to check what's happening on the back end. You may have data policies, business rules or scripts that are rejecting your change.
If not, do a simple test. Write a simple client script against a test table that will simply do the same as you back end function in terms of taking data and returning as date in the format yyyy-mm-dd and see if it will save.
Hope this helps.
:{)
:{)
Helpful and Correct tags are appreciated and help others to find information faster