Modal not saving value to Contract form.

Aaron Duncan
Mega Sage

I setup a ui page to be triggered by a UI Action. This popup allows the user to attach a document, set whether the contract is terminated with cause (a checkbox), and update the end date of the contract.

 

AaronDuncan_0-1678316058937.png

I cannot for the life of me figure out how to update the values back on the main form when selecting 'Submit Termination'.

 

Here's the 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>

  <j:set var="jvar_i" value="0" /> 
  <j:set var="jvar_Contract_ends" value="${RP.getWindowProperties().get('contract_end_date')}" />
  <j:set var="jvar_term_with_cause" value="${RP.getWindowProperties().get('u_termed_with_cause')}" />
  <j:set var="jvar_contact_starts" value="${RP.getWindowProperties().get('contract_start_date')}" /> 
  <j:set var="jvar_sys_id" value="${RP.getWindowProperties().get('sys_id')}" />
  <j:set var="jvar_row_count" value="${RP.getWindowProperties().get('row_count')}" /> 

	<g:evaluate>
		var contractGr = new GlideRecord("ast_contract");
		var fields = ["ends", "u_term_with_cause"];
		var contractLabels = {};
		fields.forEach(function(fieldName) {
			contractLabels[fieldName] = contractGr.getElement(fieldName).getLabel();
		});
		contractLabels;
	</g:evaluate>
	
<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="contract_sys_id" value="${jvar_sys_id}"/>
     <input type="hidden" name="rowCount" value="${jvar_row_count}"/>
	 <j2:if test="$[!empty(sysparm_domain)]">
		 <input type="hidden" id="sysparm_domain" name="sysparm_domain" value="${sysparm_domain}"/>
	 </j2:if>
	 <j2:if test="$[!empty(sysparm_domain_scope)]">
		 <input type="hidden" id="sysparm_domain_scope" name="sysparm_domain_scope" value="${sysparm_domain_scope}" />
	 </j2:if>
	<tr>
	<td><b>Mandatory: Add Termination Letter</b><br/>
<a onclick="saveAttachment(g_form.getTableName(), g_form.getUniqueValue())">Attach here</a>
<b></b></td>
	</tr>
     <tr>
	   <td width="50%">
<div class="form-group form-horizontal">
	<div class="col-md-8 text-right">
		<g:form_label>
				${contractLabels.u_term_with_cause}
		</g:form_label>
	</div>
	<div>
			<g:ui_checkbox name="termed_with_cause" id="termed_with_cause" value="${jvar_term_with_cause}" />
	</div>
</div>		
	   </td>
		 
		 <td width="50%">
<div class="form-group form-horizontal">
	<div class="col-md-4 text-right">
		<g:form_label>
			${contractLabels.ends}
		</g:form_label>
	</div>
	<div class="col-md-8">
           <g:ui_date name="contract_ends" id="contract_ends" value="${jvar_Contract_ends}" onchange="datePicked(this.value);" />
	</div>
</div>		
	   </td>		
		<td width="50%"></td>
    </tr>
	<tr>
		<td>
			<br />
		</td>
	</tr>
	<tr>
    <td colspan="2">
       <div id="startErrorMessage"></div>
    </td>
</tr>
<tr>
    <td colspan="2">
       <div id="endErrorMessage"></div>
    </td>
</tr>
        <tr id="dialogbuttons">
            <td colspan="4" align="right">
                <g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('Submit Termination')}" ok="return actionOK()" ok_type="button" cancel_type="button"  cancel="cancel()"/>
            </td>
        </tr>
</table>
</g:ui_form>
</j:jelly>

 

Here's the Client Script:

//Getting Error: Form submission canceled because the form is not connected. This is when I submit the modal. 
function actionOK() {
    var contractEnds = gel('contract_ends').value;
    var contractID = gel('contract_sys_id');
    var withCause = gel('termed_with_cause').value;

    var attachments = document.getElementById('header_attachment_list_label');
    if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
        alert('You must attach the Termination Letter before submitting this request.');
        return false;
    } else {
        var c = gel('cancel_or_submit');
        c.value = "submit";
        var e = gel('error');
        if (e.value == "false") {
            //alert("No Error, inside If statement line 16.");
// 			g_form.setValue('state', 'active');
// 			g_form.setValue('substate', 'pending_termination');
// 			g_form.setValue('ends', contractEnds);
// 			g_form.setValue('u_term_with_cause', withCause);
// 			g_form.setValue('renewable', false);
           gsftSubmit(gel('sysverb_update_and_stay'));
			
            GlideDialogWindow.get().destroy();
            return true;
        } else {
            return false;
        }
    }

}
//}

function cancel() {
    GlideDialogWindow.get().destroy();
    reloadWindow(window); //Refresh the form
    return false;
}

 

Here's the Processing Script:

// if (cancel_or_submit == "submit" && error == "false") {
var contract = new GlideRecord("ast_contract");
if (contract.get(contract_sys_id) && contract.canWrite()) {
    contract.ends = contractEnds;
    contract.substate = 'pending_termination';
    if (termed_with_cause == true) {
        contract.u_term_with_cause = true;
    }
    contract.renewable = false;
    contract.update();
}
// }

var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);

 

1 ACCEPTED SOLUTION

@Ankur Bawiskar , I found the solution. It was an ACL blocking the End Date field from being updated. I added an ACL to allow the update and an UI Policy to keep the user from directly updating the End Date field outside the modal. It now updates as expected. Thank you for your assistance!

View solution in original post

7 REPLIES 7

Aaron Duncan
Mega Sage

I updated the client script to actually update the values. I realized I had commented it out the portion needed to update the form. I added g_form.save(); and when the page reloads, the End Date (ends) field does not save. All others appear to update now. Any idea of what is preventing that one field from updating?

 

//Getting Error: Form submission canceled because the form is not connected. This is when I submit the modal. 
function actionOK() {
    var contractEnds = gel('contract_ends').value;
    var contractID = gel('contract_sys_id');
    var withCause = gel('termed_with_cause').value;

    var attachments = document.getElementById('header_attachment_list_label');
    if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
        alert('You must attach the Termination Letter before submitting this request.');
        return false;
    } else {
        var c = gel('cancel_or_submit');
        c.value = "submit";
        var e = gel('error');
        if (e.value == "false") {
            g_form.setValue('state', 'active');
            g_form.setValue('substate', 'pending_termination');
            g_form.setValue('ends', contractEnds);
            g_form.setValue('u_term_with_cause', withCause);
            g_form.setValue('renewable', false);
			g_form.save();
            //           gsftSubmit(gel('sysverb_update_and_stay'));

            GlideDialogWindow.get().destroy();
            return true;
        } else {
            return false;
        }
    }

}
//}

function cancel() {
    GlideDialogWindow.get().destroy();
    reloadWindow(window); //Refresh the form
    return false;
}

 

@Ankur Bawiskar , I found the solution. It was an ACL blocking the End Date field from being updated. I added an ACL to allow the update and an UI Policy to keep the user from directly updating the End Date field outside the modal. It now updates as expected. Thank you for your assistance!

@Aaron Duncan 

Glad to know.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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