AnsweredAssumed Answered

dynamic multi-select from API call

Question asked by Sergio Barrios on Oct 18, 2017
Latest reply on Nov 3, 2017 by Francesca Shiekh

Hello

 

    what i'm trying to achieve here is to make an API call and use the retrieved values to generate a dynamic multi-select field and be able to save selected options. I have used HOWTO: Have a dropdown field that get's it's options from a function as a start point with no success. This is what i did:

 

1- created a new dropdown from dropdown editor named test_users_list to attach it to the multi-select field below. The reason i created this list was b/c when you create a multi-select field from studio it can't be empty and i didn't want to use any of the existing ones.

 

2- created a new multi-select field on campaigns (using dropdown list from step 1) that created the following file

custom/Extension/modules/Campaigns/Ext/Vardefs/sugarfield_test_users_c.php

3- inside that file it contained

<?php
// created: 2017-10-19 03:23:07

$dictionary['Campaign']['fields']['test_users_c']['labelValue']='test users';
$dictionary['Campaign']['fields']['test_users_c']['dependency']='';
$dictionary['Campaign']['fields']['test_users_c']['visibility_grid']='';

?>

4- proceeded to create the function as advised on the HOWTO and my file ended up like this

<?php
// created: 2017-10-19 03:23:07
function getUsers() {
$ch = curl_init('https://jsonplaceholder.typicode.com/users');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$userss = json_decode($result, true);

$userList = array();
$userList['']='';
foreach ($userss as $i => $userx) {
$userList[$userss[$i]['username']]=$userss[$i]['name'];
}

return $userList;
}
unset($dictionary['Campaign']['fields']['test_users_c']['options']);
$dictionary['Campaign']['fields']['test_users_c']['function']='getUsers';
$dictionary['Campaign']['fields']['test_users_c']['labelValue']='test users';
$dictionary['Campaign']['fields']['test_users_c']['dependency']='';
$dictionary['Campaign']['fields']['test_users_c']['visibility_grid']='';

?>

 

Went to campaigns module, edited a campaign and the field is empty the array list wasn't created

 

empty multi-select

 

One thing that i noticed is that i didn't have 

$dictionary['Campaign']['fields']['test_users_c']['options']

to unset as advised on the HOWTO. I tried removing it with same results.

 

 

This HOWTO seems to be for an older version should still work for Ent 7.9.2, what could i be missing?

 

P.S. the API Call and the Array list do work i tested them separately this is how it looks the array list that should populate the multi-select

Array
(
[] =>
[Bret] => Leanne Graham
[Antonette] => Ervin Howell
[Samantha] => Clementine Bauch
[Karianne] => Patricia Lebsack
[Kamren] => Chelsey Dietrich
[Leopoldo_Corkery] => Mrs. Dennis Schulist
[Elwyn.Skiles] => Kurtis Weissnat
[Maxime_Nienow] => Nicholas Runolfsdottir V
[Delphine] => Glenna Reichert
[Moriah.Stanton] => Clementina DuBuque
)

 

please advise

Sergio

Outcomes