Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Thanks Ankur.  I now don't get any errors and my processing script seems to go all the way through as I have some log statements (simply so I could see how far it was getting before it was failing). 

However my output in to my RITM field is still blank, but it should be a date....?  I tried it in to a string field also but its still blank.

Hi Anita,

Did you try adding logs and check in processing script that date is available in that

Why these 2 lines are present; I have removed those and try now; you are already doing query using get()

app.addQuery('u_new_contractor_end_date',request);
app.query();

Updated code:

var contractends = date;

gs.info('Date is: ' + contractends);
if(cancel_or_submit == "submit" && error == "false") {
var app = new GlideRecord("sc_req_item");
app.get(ritm_sys_id);
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

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

So I added above and in my log I get:

14:00:44.281 Date is: 29-05-2020

And my field on my RITM now has a date 🙂

All be it the date is 10-11-0034.  I suspect I need to perform a glidedatetime query?  I expected because I was using a date picker the formatting would be ok 😞

 

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

All working.  Thank you so much Ankur, you're a diamond!