rbf_getRelatedFields help with syntax - not getting value - Forum - Rollbase - Progress Community

rbf_getRelatedFields help with syntax - not getting value

 Forum

rbf_getRelatedFields help with syntax - not getting value

  • I am trying to retrieve the values of fields from a related object. It keeps returning "undefined" instead of the value it should be. What am I doing wrong? /* */
  • I will add example to Chapter 7
  • Pavel - could you see the code I added. I thought I was remarking it out so you could see it.

  • Your code seems to be correct. I'll check in my dev. environment.
  • Pavel,



    I also tried the rbf_getFields with same result of "Undefined". I tried several different fields and field types with no luck.



    The field above application_type is an actual field on the related table. Just want to make sure that is correct? Though I also tried it with a related field on this object using getFields and it was the same result.



    Thanks,

    Parker
  • Please verify that you're using correct relationship name (object name for rbf_getFields) and correct fields names.



    I would recommend try the same API on server side script - server side has more options for debugging.
  • It seems like there is a bug in this API, I'll post a fix over weekend.
  • Hi Parker,



    Have you tried to segregate your callback function and instead of an anonymous function connected to the api call, place it in another function?



    maybe something like ::



    rbf_getRelatedFields("request", {!id}, "application_type_gr",receive);



    function receive(relName, id, values) {

    //process

    }





    I've encountered the same instance while using anonymous functions as well. sometimes it does not complete the Ajax call to the server before passing data to the receiving function if it's anonymous. Not so sure in this case if Pavel said that this is an api problem, but you can try it out if you'd like.



    Hope this helps.

    Piscoso, Martin

    Rollbase
  • I am still having issues with rbf_getRelatedFields and rbf_getFields returning a value of undefined.



    Some other things I have tried:

    -Modified the permissions on each object to make sure the Query API role has View, Create, Edit, Delete permission.

    -Made sure the portal visitor and record creator had View to all the objects

    -Renamed the callback function

    -Using rbf_getFields, tried retrieving a value of a native field to the object (rather than a related field on the object) ***This works*** So if the field you are trying to get the value from is a related field on the object, it does not work.

    -Created a template field on the object to store the value of the related field in and tried to retrieve value from that- **Does not work**



    rbf_getFields example:

  • Try playing with source code of rbf_getRelatedIds Hopefully you can find a reason for your troubles.





    function rbf_getRelatedIds(relName, id, callback) {

    var ajaxRreq = rbf_getXMLHTTPRequest();

    if (!ajaxRreq)

    return;



    ajaxRreq.onreadystatechange = function() {

    if (ajaxRreq.readyState == READY_STATE_COMPLETE) {

    var jsResponse = ajaxRreq.responseText;

    if (rbf_checkAjaxError(jsResponse))

    return;

    var idsArray = eval('(' + jsResponse + ')');

    callback(relName, id, idsArray);

    }

    };



    var url = rbf_getAjaxURL()+"&cmd=apiGetRelIds&output=json&relName="+relName+"&id="+id;

    ajaxRreq.open("GET", url, true);

    ajaxRreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

    ajaxRreq.send(null);

    }



  • After examining the source code for rbf_getFields, it appears as though our usage is correct and the problem lies within an internal cmd that's being called with the AJAX API.The cmd is "apiGetFields," and even though we are using it correctly, it is returning an object with the fields that it should be returning but all the values are null, which is incorrect.



    Since this is a problem lying in the AJAX API, we cannot debug it any further, so please advise us on what to do next to resolve this.
  • I verified that this API actually works fine when correct parameters are passed. Since you're not giving me more info it is difficult for me to help further.
  • Can you fetch "name" and "id" fields and also print out two first parameters received by callback function?



    BTW, where and when you're calling rbf_getFields API ? Are you sure that page is loaded? And all parameters are passed correctly?



    Unless you provide some info it is difficult for me to help you.
  • Hi Parker,



    I was reading through your posts. I think the problem lies in the "trying to get a field from another object" part.



    Quote from post above:

    -Using rbf_getFields, tried retrieving a value of a native field to the object (rather than a related field on the object) ***This works*** So if the field you are trying to

    get the value from is a related field on the object, it does not work.



    ---> rbf_getFields will work on the same object.

    ---> To get fields from another object you will use rbf_getRelatedFields.

    ---> rbf_getRelatedFields API will cater to "Related Field" Types ONLY (as per my experience)



    e.g.

    Object A - House

    Object B - People,

    Rel Type - 1 House Many People.



    - to use rbf_getRelatedFields here in this scenario, you will have to create a field with the type of "Related Field"

    e.g. People > New Field > Related Field > Related Object = House > Select a field.



    - Note that you can only create this on the child object People to reference it's parent object