Object Output to String Upon GlideAjax

win b
Mega Guru

Hi can you help me on this. i know its kind of correct but i think i missed on some steps on the ff scenario for retrieving the value of serial number in the cmbd_ci table. on my client script i did an onchange script were it gives me the value of the serial number but upon setting the value it display as an object not on string. 
find_real_file.png

in my Script Include(SI) here is what i did.

find_real_file.png

and upon running in my portal this is what i got
on my first alert find_real_file.png

on my second alert
find_real_file.png
what i got on the setvalue is obj which supposed to be the serial number 
find_real_file.png

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @win b ,

No need to JSON just you can do like below in script include 

Remove the JSON and 7th and 15th line script include 

return existing.serial_number.toString();

 

Client script:

remove 17th line and just set the answer to the variable in set value

g_form.setValue('change_request_no',answer);

 

Hope this helps

Please mark my answer correct if this helps you

 

View solution in original post

13 REPLIES 13

@win b if you are sending the serial number from client side then your query in glide record should be with serial number but we are comparing with sys_id so try this script include

i hope your on change variable that is serial_numb contains the serial number but not the sys_id of the cmdb_ci.

What type of field is serial_numb ?

(SI)
    getSerialNo: function() {
        var sysID = this.getParameter('sysparm_sysID');
        var existing = new GlideRecord('cmdb_ci');
existing.addQuery('serial_number',sysID);
existing.query();

        if (existing.next()) {
           return existing.serial_number.toString();
       }

       
    },

@Mohith Devatte i think we got it on the last SI you sent. 
the field of serial_numb is only a single line text.

my change request no. got a value now. only thing which bothers me next is when the field change to empty it may get the empty fields on the serial number. which it supposed to be not included 

@win b then what you can do is run the client script only when newValue is not empty like below 

if(newValue!='')
{
var ga = new GlideAjax('SI_for_Generic_CMDB');
    ga.addParam('sysparm_name', 'getSerialNo');
    ga.addParam('sysparm_sysID', newValue);
    ga.getXML(Callback);
}


   function Callback(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
   
        alert('my obj-> ' + answer);

        g_form.setValue('change_request_no',answer);
}

Hope this helps 

please mark my answer correct if this helps you

@Mohith Devatte its working now. thank you very much for the help. I also learned things on this.

MrMuhammad
Giga Sage

Hi,

Few things to modify here.

As you client script is already on the serial_numb variable so you should use newValue in the script instead of g_from.getValue('serial_numb');

No need to use JSON as there is only one value that needs to be returned. So just return inside if statement like this

if() {

return existing.getValue('serial_number');

}

in the client script just set the answer to change_request_no variable like this.

g_form.setValue('change_request_no',answer);

Regards,

Muhammad

 

Regards,
Muhammad