- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 04:50 AM
Hi All
I'm creating a UI page for end user input of a date.
Everything works fine until the Processing Script goes to read the value chosen in my date picker, it comes back as "undefined". However checking my logs I can clearly see that contract_ends is set to what I have chosen.
12:00:46.450 #276200 /ui_page_process.do Parameters ------------------------- sys_id=998a29a9dbbc185007cdfd431d961993 contract_ends,=28-05-2020
When the processing script kicks in my log states:
12:00:46.486 Unparseable date: "undefined": java.text.ParseException: Unparseable date: "undefined": java.text.DateFormat.parse(DateFormat.java:366)
I don't think I'm passing the contract_ends correctly...... Prior to adding the var statement in to my Processing Script I was getting:
12:40:27.374 Evaluator: org.mozilla.javascript.EcmaError: "contractends" is not defined.
I've also tried without ' marks and with " marks.
Here is my UI page:
HTML
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<g:evaluate var="ritm_id">
var ritm_id = RP.getParameterValue("ritm_id");
ritm_id;
</g:evaluate>
<j:set var="jvar_i" value="0" />
<j:set var="jvar_ritm_sys_id" value="${ritm_id}" />
<table width="100%">
<input type="hidden" name="cancel_or_submit" id="cancel_or_submit" value=""/>
<input type="hidden" name="error" id="error" value="false"/>
<input type="hidden" name="ritm_sys_id" value="${jvar_ritm_sys_id}"/>
<tr>
<td width="50%">
<div class="form-group form-horizontal">
<div class="col-md-4 text-right">
<p><span style="font-family: helvetica; font-size: 10pt;">
Please input the new Contract end date:
<p></p>
</span></p>
</div>
<div class="col-md-8">
<g:ui_date id="contract_ends" name="contract_ends," value="${jvar_contract_ends}" onchange="datePicked(this.value);" label="${gs.getMessage('Select Date')}" />
</div>
</div>
</td>
</tr>
<tr id="dialogbuttons">
<td colspan="4" align="right">
<g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('OK')}" ok="return actionOK();" cancel="return cancel();"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
Client Script
var contractends = gel("contract_ends").value;
function actionOK() {
var c = gel('cancel_or_submit');
c.value = "submit";
var e = gel('error');
if(e.value == "false")
return true;
else return false;
}
function cancel() {
var c = gel('cancel_or_submit');
c.value = "cancel";
return true;
}
Processing Script
var contractends = 'contract_ends'.value;
if(cancel_or_submit == "submit" && error == "false") {
var app = new GlideRecord("sc_req_item");
app.get(ritm_sys_id);
app.addQuery('u_new_contractor_end_date',request);
app.query();
app.setValue('u_new_contractor_end_date', contractends);
app.update();
}
Any advice or assistance is appreciated 🙂 I'm fairly new to scripting and coding.
Thanks
Anita
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 06:15 AM
Hi Anita,
so you are now able to get date; but not setting properly in target date field
please set it as below; converting to glide date time and then get date
var contractends = date;
var gdt = new GlideDateTime(contractends);
contractends = gdt.getDate();
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
05-19-2020 05:00 AM
Hi,
Use this:
var contractends = contract_ends;
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:20 AM
Hi Ashutosh
Tried and I get
13:19:01.212 Evaluator: org.mozilla.javascript.EcmaError: "contract_ends" is not defined.
Thanks
Anita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:29 AM
Hi Anita,
try adding alert in the client script code
Also place this line inside actionOK() method
function actionOK() {
var contractends = gel("contract_ends").value;
alert(contractends);
var c = gel('cancel_or_submit');
c.value = "submit";
var e = gel('error');
if(e.value == "false")
return true;
else return false;
}
function cancel() {
var c = gel('cancel_or_submit');
c.value = "cancel";
return true;
}
Regards
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
05-19-2020 05:34 AM
Hi Anita,
that it not how you can access the variable value from HTML in the processing script;
please see updated code below; you need to set hidden variable; in client script set the value and then access it directly in the processing script
This should definitely work
HTML: Few corrections
1) see in bold highlighted -> add hidden html element to store date; remove comma from name="contract_ends"
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<g:evaluate var="ritm_id">
var ritm_id = RP.getParameterValue("ritm_id");
ritm_id;
</g:evaluate>
<j:set var="jvar_i" value="0" />
<j:set var="jvar_ritm_sys_id" value="${ritm_id}" />
<table width="100%">
<input type="hidden" name="cancel_or_submit" id="cancel_or_submit" value=""/>
<input type="hidden" name="error" id="error" value="false"/>
<input type="hidden" name="ritm_sys_id" value="${jvar_ritm_sys_id}"/>
<input type="hidden" name="date" id="date" value=""/>
<tr>
<td width="50%">
<div class="form-group form-horizontal">
<div class="col-md-4 text-right">
<p><span style="font-family: helvetica; font-size: 10pt;">
Please input the new Contract end date:
<p></p>
</span></p>
</div>
<div class="col-md-8">
<g:ui_date id="contract_ends" name="contract_ends" value="${jvar_contract_ends}" onchange="datePicked(this.value);" label="${gs.getMessage('Select Date')}" />
</div>
</div>
</td>
</tr>
<tr id="dialogbuttons">
<td colspan="4" align="right">
<g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('OK')}" ok="return actionOK();" cancel="return cancel();"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
Client Script: get the value and set in hidden variable
1) push that line inside the function and set in hidden html input variable
function actionOK() {
var contractends = gel("contract_ends").value;
gel("date").value = contractends;
var c = gel('cancel_or_submit');
c.value = "submit";
var e = gel('error');
if(e.value == "false")
return true;
else return false;
}
function cancel() {
var c = gel('cancel_or_submit');
c.value = "cancel";
return true;
}
Processing Script:
var contractends = date;
if(cancel_or_submit == "submit" && error == "false") {
var app = new GlideRecord("sc_req_item");
app.get(ritm_sys_id);
app.addQuery('u_new_contractor_end_date',request);
app.query();
app.setValue('u_new_contractor_end_date', contractends);
app.update();
}
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