rbf_getRelatedFields help with syntax - not getting value

Posted by Rollbase User on 07-Jun-2012 11:38

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? /* */

All Replies

Posted by Admin on 07-Jun-2012 12:26

I will add example to Chapter 7

Posted by Admin on 07-Jun-2012 13:32

Pavel - could you see the code I added. I thought I was remarking it out so you could see it.

Posted by Admin on 07-Jun-2012 13:47

Posted by Admin on 07-Jun-2012 14:07

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

Posted by Admin on 07-Jun-2012 16:02

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

Posted by Admin on 07-Jun-2012 17:14

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.

Posted by Admin on 07-Jun-2012 18:10

It seems like there is a bug in this API, I'll post a fix over weekend.

Posted by Admin on 07-Jun-2012 19:52

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

Posted by Admin on 18-Jun-2012 14:31

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:

Posted by Admin on 18-Jun-2012 18:40

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);

}



Posted by Admin on 24-Jun-2012 20:31

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.

Posted by Admin on 24-Jun-2012 23:11

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.

Posted by Admin on 24-Jun-2012 23:32

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.

Posted by Admin on 25-Jun-2012 06:20

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

Posted by Admin on 25-Jun-2012 10:05

Parker,



what is data type of field(s) you're trying to retrieve?

Posted by Admin on 25-Jun-2012 13:49

Hi Martin,



Thanks so for your helpful response. I am actually trying to use both/either the rbf_getFields and rbf_getRelatedFields. For example:



I have a field on the Request Object (parent object) called Type of Request (type_of_request1), this is a picklist field and is saved with each Request object record. I need to use this value on my child object (CIG Details) portal pages, Add/Edit/View CIG Details. There is a one to one relationship between Requests->CIG Details. So to get that value, I am using this. I am using rbf_getRelatedFields to pull the value from the "type_of_request1" on the Requests object. This is on a test page to make sure that I have nothing else interfering. This script runs and returns a value of "Undefined" when it should return a value of: "Project".



Posted by Admin on 25-Jun-2012 19:20

Hi Parker,



I see where your coming from now. see below:



Update: rbf_getRelatedFields seems to work on any relationship now and from any originating object, contrary to my previous post.

- This is great @Pavel =)



What I've noticed: It works on ANY relationship type AND field type now, so we are not bound to Related Fields anymore. I've tried using it on a many is to one relationship coming from the "many" record and still got values, although I've found that it is now limited to get the values from just one field.

In the case that there are more than one return values, they will be comma separated : a, b, c, d etc. when you use the return parameter, or you can alternatively use it as an array, param[0], param[1], param[2], etc. for singular values.



Here are some notes:



- Are you sure that the integration name "type_of_request1" is the one that is on the Request object?



- on the Add/Edit/View CIG Details pages, is it already related to a Request record or are you

Posted by Admin on 25-Jun-2012 19:59

Formula fields may not work well with client-side API: this will be fixed in the next release.



Running alert(values) would be a great way to clarify situation further.

This thread is closed