Glide Ajax - Accessing an object within returned payload

Community Alums
Not applicable

Hi,

So I built a Glide Ajax that allows me to look up a record and return the entire record as an object. Within that record are then other reference fields. In this instance I'm trying to get the sys_id stored in u_item_no, but I'm stuck on how to access it.

Client script funtion is below: 

function getOverNightShip() {
    var assetLookup = new GlideAjax('TableGlideAjax');
    assetLookup.addParam('sysparm_name', 'getRecord');
    assetLookup.addParam('sysparm_table', 'alm_hardware');
    assetLookup.addParam('sysparm_lookupField', 'ci');
    assetLookup.addParam('sysparm_lookupValue', g_form.getValue('cmdb_ci'));
    assetLookup.getXML(getDin);

    function getDin(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var assetRec = JSON.parse(answer);
        alert(String(assetRec.u_item_no));
}

This triggers an alert that shows [Object, Object], if I stringify I can see the contents are 

    "u_item_no": {
        "#text": "fb631006db030014c51df9051d961905",
        "@display_value": "211040"
    }

 

Obviously it won't let me do assetRec.u_item_no.#text so how would I go about pulling that value?

 

Any help is appreciated, thank you.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

I was being stupid, I managed to figure it out...

 

assetRec.u_item_no["#text"] gives me the sys_id

View solution in original post

1 REPLY 1

Community Alums
Not applicable

I was being stupid, I managed to figure it out...

 

assetRec.u_item_no["#text"] gives me the sys_id