UI Page: get the sysId of the calling form in Processing Script

andy_dufresne
Tera Expert

Hello Gurus,

I have form on which we have a 'send SMS' button, when clicked will bring up a UI page, which has a code something like this ..

<g:ui_form>

<input type="hidden" id="cancelled" name="cancelled" value="false"/>

<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>

<table>

<tr>

<td id="label.location" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="location" onclick="" dir="">Users:</label></td>

<td nowrap="true"><g:ui_reference name="location" id="location" table="sys_user" onchange="user_data()"/></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0">

<tr><td nowrap="true"><g:ui_input_field label="First Name" name="first_name" id="first_name" mandatory="true" size="50" /></td></tr>

<tr><td nowrap="true"><g:ui_input_field label="Last Name" name="last_name" id="last_name" mandatory="true" size="50" /></td></tr>

<tr><td nowrap="true"><g:ui_input_field label="Email" name="email" id="email" mandatory="true" size="100"/></td></tr>

<tr><td nowrap="true"><g:ui_input_field label="Business Phone" name="phone" id="phone" mandatory="true" size="40" /></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0">

<tr><td nowrap="true"><g:ui_input_field label="SMS Text" name="sms_text" id="sms_text" mandatory="true" size="50" /></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0">

<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm()" ok_type="submit" cancel="return onCancel();"/></td></tr>

</table>

</g:ui_form>

I want to do a gs.addInfoMessage() on the sys_id of the calling form [aka the form where the 'send sms' button was there].   how do i get it in the   Processing script?

There is more functionality I can implement once I get the sys_id.

Any help?

Thanks in Advance

1 ACCEPTED SOLUTION

Here are the changes. I have tested and it is working


UI action:


function smsDialog() {


var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;


//var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;


var gDialog = new GlideDialogWindow("Send_sms"); ////Render the dialog containing the UI Page


gDialog.setTitle("Send SMS");


//gDialog.setPreference("incidentSysID", g_form.getUniqueValue());


gDialog.setPreference('sysparm_sysID', sysId);


//gDialog.setPreference('sysparm_table', "incident_alert");


gDialog.render();


}


UI page:


<g:ui_form>


<input type="hidden" id="cancelled" name="cancelled" value="false"/>


<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>


<!--<g:evaluate var="jvar_incidentSysId" expression="RP.getWindowProperties().get('incidentSysId')" />-->


<!--<input type="hidden" id="incidentSysID" value="${jvar_incidentSysId}" />   -->


<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>


<table>


<tr>


<td id="label.location" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="location" onclick="" dir="">Users:</label></td>


<td nowrap="true"><g:ui_reference name="location" id="location" table="sys_user" onchange="user_data()"/></td></tr>


</table>



<table width="100%" cellpadding="0" cellspacing="0">


<tr><td nowrap="true"><g:ui_input_field label="First Name" name="first_name" id="first_name" mandatory="true" size="50" /></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Last Name" name="last_name" id="last_name" mandatory="true" size="50" /></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Email" name="email" id="email" mandatory="true" size="100"/></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Business Phone" name="phone" id="phone" mandatory="true" size="40" /></td></tr>


</table>



<table width="100%" cellpadding="0" cellspacing="0">


<tr><td nowrap="true"><g:ui_input_field label="SMS Text" name="sms_text" id="sms_text" mandatory="true" size="50" /></td></tr>


</table>




<table width="100%" cellpadding="0" cellspacing="0">


<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm()" ok_type="submit" cancel="return onCancel();"/></td></tr>


</table>


</g:ui_form>


View solution in original post

14 REPLIES 14

I did that and it was blank, Ankur.   Here is the raw text of all my script, I have to remove one line where it actually sends SMS but I seriously doubt if that is blocking it.



Ok starting with the 'UI action', this is the code for 'send sms':



function smsDialog() {


//var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;


var gDialog = new GlideDialogWindow("Send_sms"); ////Render the dialog containing the UI Page


gDialog.setTitle("Send SMS");


gDialog.setPreference("incidentSysID", g_form.getUniqueValue());


//gDialog.setPreference('sysparm_sysID', sysId);


//gDialog.setPreference('sysparm_table', "incident_alert");


gDialog.render();


}



This is the code in the html section:


<g:ui_form>


<input type="hidden" id="cancelled" name="cancelled" value="false"/>


<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>


<g:evaluate var="jvar_incidentSysId" expression="RP.getWindowProperties().get('incidentSysId')" />


<input type="hidden" id="incidentSysID" value="${jvar_incidentSysId}" />


<table>


<tr>


<td id="label.location" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="location" onclick="" dir="">Users:</label></td>


<td nowrap="true"><g:ui_reference name="location" id="location" table="sys_user" onchange="user_data()"/></td></tr>


</table>



<table width="100%" cellpadding="0" cellspacing="0">


<tr><td nowrap="true"><g:ui_input_field label="First Name" name="first_name" id="first_name" mandatory="true" size="50" /></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Last Name" name="last_name" id="last_name" mandatory="true" size="50" /></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Email" name="email" id="email" mandatory="true" size="100"/></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Business Phone" name="phone" id="phone" mandatory="true" size="40" /></td></tr>


</table>



<table width="100%" cellpadding="0" cellspacing="0">


<tr><td nowrap="true"><g:ui_input_field label="SMS Text" name="sms_text" id="sms_text" mandatory="true" size="50" /></td></tr>


</table>




<table width="100%" cellpadding="0" cellspacing="0">


<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm()" ok_type="submit" cancel="return onCancel();"/></td></tr>


</table>


</g:ui_form>



This is the code in the 'Client Script' section:


function onCancel() {


var c = gel('cancelled');


c.value = "true";


GlideDialogWindow.get().destroy();


return false;


}


// This function is called once user is selected on the UI Page


function user_data() {


var userui = $('location').value;


//alert(userui);


var rec = new GlideRecord('sys_user');


rec.addQuery('sys_id',userui);


rec.query(dataReturned);



function dataReturned() {


// Auto Populate the Values ( first name , last name , email and Business Phone)


if(rec.next()){



$('first_name').value=rec.first_name;


$('last_name').value=rec.last_name;


$('email').value=rec.email;


$('phone').value=rec.phone;



}


}



}



This is the code in the Processing Script:


if(incidentSysID != ''){


gs.addInfoMessage('Sys id is:'+incidentSysID);


}





Here are the changes. I have tested and it is working


UI action:


function smsDialog() {


var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;


//var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;


var gDialog = new GlideDialogWindow("Send_sms"); ////Render the dialog containing the UI Page


gDialog.setTitle("Send SMS");


//gDialog.setPreference("incidentSysID", g_form.getUniqueValue());


gDialog.setPreference('sysparm_sysID', sysId);


//gDialog.setPreference('sysparm_table', "incident_alert");


gDialog.render();


}


UI page:


<g:ui_form>


<input type="hidden" id="cancelled" name="cancelled" value="false"/>


<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>


<!--<g:evaluate var="jvar_incidentSysId" expression="RP.getWindowProperties().get('incidentSysId')" />-->


<!--<input type="hidden" id="incidentSysID" value="${jvar_incidentSysId}" />   -->


<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>


<table>


<tr>


<td id="label.location" class="label" nowrap="true" height="23px" type="string" choice="0"><span id="status." class="mandatory label_description" mandatory="true" oclass="mandatory">$[SP]</span><label for="location" onclick="" dir="">Users:</label></td>


<td nowrap="true"><g:ui_reference name="location" id="location" table="sys_user" onchange="user_data()"/></td></tr>


</table>



<table width="100%" cellpadding="0" cellspacing="0">


<tr><td nowrap="true"><g:ui_input_field label="First Name" name="first_name" id="first_name" mandatory="true" size="50" /></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Last Name" name="last_name" id="last_name" mandatory="true" size="50" /></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Email" name="email" id="email" mandatory="true" size="100"/></td></tr>


<tr><td nowrap="true"><g:ui_input_field label="Business Phone" name="phone" id="phone" mandatory="true" size="40" /></td></tr>


</table>



<table width="100%" cellpadding="0" cellspacing="0">


<tr><td nowrap="true"><g:ui_input_field label="SMS Text" name="sms_text" id="sms_text" mandatory="true" size="50" /></td></tr>


</table>




<table width="100%" cellpadding="0" cellspacing="0">


<tr><td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm()" ok_type="submit" cancel="return onCancel();"/></td></tr>


</table>


</g:ui_form>


Ankur, Abhinay and Gaetano: Thanks immensely for taking time to solve my issue.   I REALLY appreciate your help. I'm glad I belong to this forum! Have a lovely day, folks! Thanks again!


can you paste the scripts here rather than screenshots, that will be easier for me edit the code.


Abhinay Erra
Giga Sage

You bet!