UI Page Processing Script Issue

Anita Parrott
Kilo Contributor

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

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

In principal we can directly access the element by using ID of that element.

I can see it works for me.

Thanks,

Ashutosh