Passing form values into a Processing Script

zschneider
Kilo Expert

I'd like to update the comments field for a ticket in a ui page and am having trouble figuring out how to pass the value from a textarea field int othe processing script.

In my HTML I have this:


<g:ui_form>
       <g:dialog_buttons_ok_cancel ok="return true" />
       <input type="hidden" name="incident_id" value="SYS_ID_OF_TICKET"/>
       <textarea id="comments" name="comments"></textarea>
 </g:ui_form>


My processing script has this:

var inc = new GlideRecord('incident');
inc.get(incident_id);
inc.comments  = document.getElementById('comments');
inc.work_notes = "this is a test";
inc.update();
var urlOnStack = Packages.com.glide.sys.GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);


document.getElementById('comments'); does not work and I'm really not sure what to put here to pull the value from the comments textarea into the processing script. If it's possible to do inc.get to an input field to query the table, you'd think there would be a way to pass other form fields into a business rule.

Does anyone have any idea?
1 ACCEPTED SOLUTION

Chris_Hann
ServiceNow Employee
ServiceNow Employee

Try the following line instead:

inc.comments = comments;

The values of each form input are available via a variable with the same name as the name attribute of input element.

Have you considered using a cut-down version of the Form (using a View), instead of a custom UI Page?


View solution in original post

6 REPLIES 6

Chris_Hann
ServiceNow Employee
ServiceNow Employee

Try the following line instead:

inc.comments = comments;

The values of each form input are available via a variable with the same name as the name attribute of input element.

Have you considered using a cut-down version of the Form (using a View), instead of a custom UI Page?


zschneider
Kilo Expert

Thanks Chris!

I feel dumb for not trying that first 🙂

We use views for our other ESS pages, but decided to use a custom UI Page this time because it allows more control over the layout of the content. This will be a read-only data (outside of customer communication) that users will want to copy/paste. Having all the content outside of form elements makes that easier and isn't as big an eyesore as a bunch of grayed out form fields.

Thanks again for the help!


Chris_Hann
ServiceNow Employee
ServiceNow Employee

My pleasure, make sure you check the user has the rights to update the comments field (


inc.comments.canWrite()
), before updating the record.

SN Wiki: GlideRecord.canWrite


atulchauhan
Kilo Contributor

Hi Zach,



Are you able to write into work_notes field by processing script?


I am having same requirement but facing issue.



Please let me know if your functionality is working fine.



Thanks & Regards,


Atul Chauhan