Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

First, I'm using sugarcrm pro 6.5 and accessing via rest v4, so I have this array that's being returned from printing $results that is working fine:

    stdClass Object
(
 [result_count] => 2000
 [total_count] => 3390
 [next_offset] => 2000
 [entry_list] => Array
    (
      [0] => stdClass Object
            (
                [id] => 77da301b-83dd-4fe6-e38f-53ba151fb084
                [module_name] => Leads
                [name_value_list] => stdClass Object
                    (
                        [id] => stdClass Object
                            (
                                [name] => id
                                [value] => 77da301b-83dd-4fe6-e38f-53ba151fb084
                            )

                        [name] => stdClass Object
                            (
                                [name] => name
                                [value] => Jim Beam
                            )

                        [status] => stdClass Object
                            (
                                [name] => status
                                [value] => Dead
                            )

                        [website] => stdClass Object
                            (
                                [name] => website
                                [value] => website.com
                            )

                        [phone_cr] => stdClass Object
                            (
                                [name] => phone_cr
                                [value] => 1-888-888-8888
                            )

                    )

            )

        [1] => stdClass Object
            (
                [id] => d0ecc069-d556-98f3-41f2-53ba1468327a
                [module_name] => Leads
                [name_value_list] => stdClass Object
                    (
                        [id] => stdClass Object
                            (
                                [name] => id
                                [value] => d0ecc069-d556-98f3-41f2-53ba1468327a
                            )

                        [name] => stdClass Object
                            (
                                [name] => name
                                [value] => John Doe
                            )

                        [status] => stdClass Object
                            (
                                [name] => status
                                [value] => New
                            )

                        [website] => stdClass Object
                            (
                                [name] => website
                                [value] => web.com
                            )

                        [phone_cr] => stdClass Object
                            (
                                [name] => phone_cr
                                [value] => 1-888-888-8888
                            )

                    )

            )

I'm using a query from the api to filter the results for the user I'm targeting:

    'query' => "leads.assigned_user_id='user_ID-here'",
     'order_by' => "date_entered DESC",

This works fine. So I've ran a foreach () statement to retrieve only one field on a button click, which also works just fine. What I really need to accomplish is before this statement, a foreach() command (or something else?) to filter out and retrieve ONLY the "New" results in the status value, and from that group output an array showing only the website field. Seen in the "desired end result section of this question."

This is the code I'm filtering the field I'm targeting and having a new array created with if that helps bridge the gap:

    $results = call('get_entry_list', $params, $url);
    $eresult = array();
    foreach ($results->entry_list as $index=>$value_list) {
    $listed = $value_list->name_value_list->website->value;
    $eresult[] = $listed;}

So the desired end result based on this data should be:

    Array
    (
    [1] => web.com
    )

I'm unsure what I need to do to filter the "Status" field to only then be ran with the $eresult array I created to achieve this. To be clear, everything is working as it should, and my print from $eresult is outputting exactly as it should by returning all results in the website value area, I just need some help to get it sorted before going to that step by sorting it by the "new" status first without all the extra 'stuff,' then sorting out the array in my desired format with the foreach() statement above. I tried to cut out all the other code, as it's a pretty long project, so this should be all the relevant information for the particular goal I need to accomplish in this segment. Any help is greatly appreciated! Thank you!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I've decided to create a second script for this as a temp solution by adding:

'query' => "(leads.assigned_user_id='user_ID-here') AND (status='New')"

So I guess that works, I was trying to avoid calling another script for just one separate function, but it is working fine.

share|improve this answer
    
You could have processed that array, but I think the second call is going to be much easier to read, annotate and maintain. –  Matthew Poer Jul 9 '14 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.