Sorting after getting the related IDs

Posted by IramK on 21-Jul-2015 06:52

Hello,

I have a picklist with values 1,2,3,4,5,6 on an object B and this object is related to object A. When I perform a rbf_getRelatedIds2 from object A to get object B records (lets say we get back 6 ID's), I get the related ID's from object B but in an unsorted manner. Is there a way that I could perform a sort of the returned values based on the picklist field such that I always get the result in a sorted ascending order? Kindly let me know.

Cheers.

Posted by Godfrey Sorita on 21-Jul-2015 12:14

Yes. You will need to put it on the callback to ensure the 2nd selectQuery is executed after the first.

$(function(){
  rbf_selectQuery("SELECT id, picklistl1#value FROM student WHERE R1234567 = {!id} order by picklistl1#value ASC", 1000, function(data){
    for(var k=0; k<data.length; k++) {
      var picklistValue = data[k][1];
      alert("Picklist Value:"+picklistValue);
    }

    rbf_selectQuery("SELECT id FROM class", 1000, function(data){
      //statement
    });
  });
});


All Replies

Posted by Godfrey Sorita on 21-Jul-2015 08:56

If you use rbf_getRelatedIds2, you will also need to query the picklist values individually then sort them using JavaScript.

The use of rbf_selectQuery API might be a better solution. Please see sample code below on how you can accomplish this requirement:

$(function(){
  rbf_selectQuery("SELECT id, picklistl1#value FROM student WHERE R1234567 = {!id} order by picklistl1#value ASC", 1000, function(data){
    for(var k=0; k<data.length; k++) {
      var picklistValue = data[k][1];
      alert("Picklist Value:"+picklistValue);
    }
  });
});


Posted by IramK on 21-Jul-2015 11:32

That saved me two API calls, merged them as one and allowed an Order By. Whilst we are at it, is it possible to call another selectQuery after this one is completed? Thanks for the answer.

Posted by Godfrey Sorita on 21-Jul-2015 12:14

Yes. You will need to put it on the callback to ensure the 2nd selectQuery is executed after the first.

$(function(){
  rbf_selectQuery("SELECT id, picklistl1#value FROM student WHERE R1234567 = {!id} order by picklistl1#value ASC", 1000, function(data){
    for(var k=0; k<data.length; k++) {
      var picklistValue = data[k][1];
      alert("Picklist Value:"+picklistValue);
    }

    rbf_selectQuery("SELECT id FROM class", 1000, function(data){
      //statement
    });
  });
});


Posted by IramK on 21-Jul-2015 12:51

Perfect Thanks!

This thread is closed