Passing text area values into a Processing Script

Feddy
Kilo Sage

Hi Team , 

I need to make worknotes mandatory when reopen action is clicked. 
The issue is the reopen action will be visible only on closed problem and the worknote field  is restricted using write ACL on closed tickets. I cannot modify a ACL. 
I have created a ui page in order to ask make the popup text area later copying the value to worknotes. Even this is not working. Please help me how to pass text area value to processing script and update the text area value to worknotes.

My Ui action Script : 

var ConfirmReopenDialog;

function reopenProblem(){    //onclick of the ui action
var sysId = g_form.getUniqueValue();
ConfirmReopenDialog = new GlideModal("pep_worknotes_dialog", false);
ConfirmReopenDialog.setTitle(new GwtMessage().getMessage("Re-open Problem"));
ConfirmReopenDialog.setPreference('sysparm_sys_id', sysId);
ConfirmReopenDialog.render();
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateProblem();

function updateProblem(){
current.state = 7;
current.update();
action.setRedirectURL(current);
}
--------------------------------------------------------------------------------------------------------------------------------------------

In my UI page, 

My HTML is 

<?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:dialog_notes_ok_cancel
dialog_id="pep_worknotes_dialog"
textarea_id="work_notes"
textarea_label="${gs.getMessage('Work notes')}"
textarea_name="work_notes"
textarea_onkeyup="enableButton()"
textarea_style="height:auto; width: 100%; resize: vertical;"
textarea_title="${gs.getMessage('Enter the reopen reason here')}"
ok=""
ok_id="confirm_ok_btn_prb"
ok_action="ReopenProblem"
ok_title="${gs.getMessage('Reopen the Problem')}"
ok_type="button"
ok_style_class="btn btn-primary disabled"
cancel_title="${gs.getMessage('Close the dialog')}"


/>
<g:ui_form>
<g:dialog_notes_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>

</j:jelly>


-------------------------------------------------------------------------------------------------------------------------

my client script in ui page is 

function ReopenProblem() {
var text = $("work_notes");
var textArea = "Reopen Reason : "+text.value.trim();
GlideModal.get().destroy();
g_form.setValue('work_notes',textArea);  ///// This is not happening since the field is restricted write acces

gsftSubmit(null, g_form.getFormElement(), "reopen_problem");
}

---------------------------------------------------------------------------------------------------------------------------


Please let me know how to get the value of text area value as well as problem sys id so that i can update the value in processing script

Thanks in Advance

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@feddy 

pass the sys_id as below

Either do GlideRecord or GlideAjax

<input type="hidden" id="incident_id" name="incident_id" value="${sysparm_sys_id}"/>

function ReopenProblem() {
var text = $("work_notes");
var textArea = "Reopen Reason : "+text.value.trim();
GlideModal.get().destroy();

var sysId = gel('incident_id').value;

var gr = new GlideRecord('problem');

gr.get(sysId);

gr.work_notes = textArea;

gr.update();

gsftSubmit(null, g_form.getFormElement(), "reopen_problem");
}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@feddy 

if that field is readonly then you cannot set it using setValue()

Also please use html input box for getting the comments

Then you can set the value using script in UI page processing script

OR

If you already have the textArea value in the client script then perform glideajax and send the value, record sys_id to be updated by that function

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

@feddy 

pass the sys_id as below

Either do GlideRecord or GlideAjax

<input type="hidden" id="incident_id" name="incident_id" value="${sysparm_sys_id}"/>

function ReopenProblem() {
var text = $("work_notes");
var textArea = "Reopen Reason : "+text.value.trim();
GlideModal.get().destroy();

var sysId = gel('incident_id').value;

var gr = new GlideRecord('problem');

gr.get(sysId);

gr.work_notes = textArea;

gr.update();

gsftSubmit(null, g_form.getFormElement(), "reopen_problem");
}

Regards
Ankur

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

It is working fine only for admin , not for other user.
I used gliderecord for now, please check my html script and client scrpit.
I haven't really had much exposure to ui pages.

please see my script below, 

<?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:dialog_notes_ok_cancel
dialog_id="pep_worknotes_dialog"
textarea_id="work_notes"
textarea_label="${gs.getMessage('Work notes')}"
textarea_name="work_notes"
textarea_onkeyup="enableButton()"
textarea_style="height:auto; width: 100%; resize: vertical;"
textarea_title="${gs.getMessage('Enter the reopen reason here')}"
ok=""
ok_id="confirm_ok_btn_prb"
ok_action="ReopenProblem"
ok_title="${gs.getMessage('Reopen the Problem')}"
ok_type="button"
ok_style_class="btn btn-primary disabled"
cancel_title="${gs.getMessage('Close the dialog')}"

/>
<g:ui_form>
<input type="hidden" id="problem_id" name="problem_id" value="${sysparm_sys_id}"/>
</g:ui_form>

</j:jelly>





My Client script is ,

function ReopenProblem() {
var text = $("work_notes");
var textArea = "Reopen Reason : " + text.value.trim();
var sysId = gel('problem_id').value;

var gr = new GlideRecord('problem');
gr.get(sysId);
gr.state='7';
gr.work_notes = textArea;

gr.update();
GlideModal.get().destroy();


gsftSubmit(null, g_form.getFormElement(), "reopen_problem");
}

Hi,

So the update is working fine with admin users

But not with non-admins?

Regards
Ankur

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