The CreatorCon Call for Content is officially open! Get started here.

To extract just a few strings from the response body of the API

tsoct
Tera Guru

Hello all,
The API response body return:

{
  "iban":"GB33BUKB20201555555555",
  "country_code":"GB",
  "checksum":"33",
  "bank_id":"BUKB",
  "branch_id":"202015",
  "account_number":"55555555",
  "length":22
}

 How can I extract only the branch ID and account number from the catalog client script?

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var iban = g_form.getValue('iban');

    var gaFields = new GlideAjax('SwiftValidation');
    gaFields.addParam('sysparm_name', 'getIBAN');
    gaFields.addParam('sysparm_iban', iban);
    gaFields.getXML(showSWIFTData);

    function showSWIFTData(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		//alert('the IBAN details: ' + answer );
        var obj = JSON.parse(answer);

       for (var i = 0; i < obj.length; i++) {
			alert('The extraction: '+obj[i].account_number ++obj[i].branch_id  );
        }
    }

}
1 ACCEPTED SOLUTION

Zach Koch
Giga Sage

If you only want the account_number and branch_id, you would just use 

obj.account_number

obj.branch_id

for your alert, that would look like this

alert('The extraction: ' + obj.account_number  + '  ' + obj.branch_id  );
If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

1 REPLY 1

Zach Koch
Giga Sage

If you only want the account_number and branch_id, you would just use 

obj.account_number

obj.branch_id

for your alert, that would look like this

alert('The extraction: ' + obj.account_number  + '  ' + obj.branch_id  );
If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!