I am trying to display list of address through Soap message via UI page and UI action

Avinash Mandapa
Tera Contributor

I am able to display list of address but I want to update address fields on the current form once the user selects any address from the list.

 


################## Script for UI action #########################
function popupDispList() {
var gdw = new GlideDialogWindow('Get_Address');
gdw.setTitle('Address List');
gdw.setPreference('sysparm_view', 'default');

gdw.setPreference('onCloseCallback', function(selectedAddress) {

g_form.setValue('short_description', selectedAddress);
});

gdw.render();
}

####################### Script for UI page ######################

<?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:evaluate>
// perform the soap lookup
var s = new sn_ws.SOAPMessageV2('CPConnect', 'addressSearch');
s.setStringParameterNoEscape('postcode', 'LE21WQ');
s.setStringParameterNoEscape('password_hash', '55626bc141c63eecf11df9accab53e6');
s.setStringParameterNoEscape('username', 'digital.space.direct.api');
var response = s.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();

// make XML of the response
var xmldoc = new XMLDocument(responseBody);
var Nodes = xmldoc.getNodes("//addressReference");

// find the total number of matches
var numofAddress = Nodes.getLength();

// create an empty variable to be filled with all matches
var allAddress = [];

for (var i = 1; numofAddress >= i; i++) {
var addressReference = xmldoc.getNodeText("//Address["+i+"]/addressReference");
// push the field to an array
allAddress.push({
addressReference: addressReference.toString(),
premisesName: xmldoc.getNodeText("//Address["+i+"]/premisesName"),
postTown: xmldoc.getNodeText("//Address["+i+"]/postTown")
});
}
</g:evaluate>

<script>
function selectAddress(addressReference) {
// Call the callback function in the parent window and pass the selected address
window.opener.gdwCloseCallback(addressReference);
// Close the current window
window.close();
}
</script>

<br/>

<h2>Number of Matches: ${numofAddress}</h2>

<p/>

Status: ${status}

<br/>

<j:if test="${numofAddress >= '1'}">
<table style="border: 1px solid black; padding: 5px;">
<tr>
<td nowrap="true" style="border: 1px solid black; padding: 5px;"><strong>Select</strong></td>
<td nowrap="true" style="border: 1px solid black; padding: 5px;"><strong>Premises Name</strong></td>
<td nowrap="true" style="border: 1px solid black; padding: 5px;"><strong>Post Town</strong></td>
</tr>
<j:forEach var='jvar_clientid' items='${allAddress}'>
<tr>
<td nowrap="true" style="border: 1px solid black; padding: 5px;">
<input type="radio" name="selectedClientID" value="${jvar_clientid.addressReference}"
onclick="selectAddress('${jvar_clientid.addressReference}')"/>
</td>
<td nowrap="true" style="border: 1px solid black; padding: 5px;">${jvar_clientid.premisesName}</td>
<td nowrap="true" style="border: 1px solid black; padding: 5px;">${jvar_clientid.postTown}</td>
</tr>
</j:forEach>
</table>
</j:if>
</j:jelly>

0 REPLIES 0