cancel
Showing results for 
Search instead for 
Did you mean: 

Loading a database table in a combobox

prpontes
Champ in-the-making
Champ in-the-making
Hello I would like to help on a one questions related to content creation. I am creating new content and with the content, new aspects. So far so good. My question is how do you add a metadata field as the type combobox in it to load data from a table Client? I need to create some Action javascript?

thank you.
11 REPLIES 11

erikwinlof
Confirmed Champ
Confirmed Champ
Hi Prpontes,

Unfortunately I don't follow exactly what you want to do, right now I'm guessing you are trying to create a form that shall appear in Share when you create new content of your custom model, and that that form shall contain a custom control shall be a combo box that shall load data from a "database table" in the repository?

If so please make sure you have read the forms documentation on how to create a custom form "control":
http://wiki.alfresco.com/wiki/Forms

Then make sure there is a json webscript available in the repo that can make the table data available through the proxy. Then use the  Alfresco.util.Ajax.jsonGet javascript method from your custom form control to load the table data from the repo.

Hope this is at least close to what your looking for, If not you have to be a bit more specific, providing some of the code you already have might help.

Cheers, Erik

prpontes
Champ in-the-making
Champ in-the-making
Hi Erik thanks for your reply, that's exactly what I want to do.

sorry for my english, is that I'm using google translator, so maybe you do not understand me.

then that's it I want to:
Create a form that contains a custom control (combo box) that has on it a table to show all my registered clients.

thanks for the help.

erikwinlof
Confirmed Champ
Confirmed Champ
Great! Then you should get a good start using that link.

Cheers, Erik

prpontes
Champ in-the-making
Champ in-the-making
Hi Erik I can export a resultset to xml and display the values ​​inside a control selectone? Because I think it would be easier to do a direct query to a table. Is there something I could do in alfresco?

thank you

erikwinlof
Confirmed Champ
Confirmed Champ
Alfresco does not let you query its database table directly from the browser and export the result as xml.
Instead take a look at the following link on how to create a repository web script coded in java. I would suggest you return json instead of xml since that is slightly easier to handle in the browser using javascript, but if you want to use xml that is fine too.

http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples

Then you will be able to access that web script form your browser using javascript, i.e. using the Alfresco.util.Ajax.request method.

Cheers, Erik

zlu
Champ in-the-making
Champ in-the-making
Hi Prpontes,

Unfortunately I don't follow exactly what you want to do, right now I'm guessing you are trying to create a form that shall appear in Share when you create new content of your custom model, and that that form shall contain a custom control shall be a combo box that shall load data from a "database table" in the repository?

If so please make sure you have read the forms documentation on how to create a custom form "control":
http://wiki.alfresco.com/wiki/Forms

Then make sure there is a json webscript available in the repo that can make the table data available through the proxy. Then use the  Alfresco.util.Ajax.jsonGet javascript method from your custom form control to load the table data from the repo.

Hope this is at least close to what your looking for, If not you have to be a bit more specific, providing some of the code you already have might help.

Cheers, Erik

Hi Erik,

Can you tell me more detail in how to call the Alfresco.util.Ajax.jsonGet in the control? In the control's template file or what?

I have the working web script but don't know how to call it and add the return jason items to the control.

erikwinlof
Confirmed Champ
Confirmed Champ
Hi,

If your new to this its probably easiest to start by creating it inline, inside the template just to get it working…

First create a combobox and assign it the unique guid that the forms runtime gives you, i.e.:

<select id="${fieldHtmlId}"></select>

Then inside a <script> tag do something like this:

var getSelectFieldData = function(fieldId)
{
   // First make sure the select element is found in the dom…
   YAHOO.util.Event.onContentReady(fieldId, function()
   {
      // …found it, now ask your custom repo webscript for the data…
      var selectEl = YAHOO.util.Dom.get(fieldId);
      Alfresco.util.Ajax.jsonGet(
      {
         url: Alfresco.constants.PROXY_URI + '/your/custom/webscript',
         successCallback:
         {
            fn: function loadWebscript_successCallback(response, config)
            {
               // …data is now received, now populate the select element
               // todo: Add <option> elements to "selectEl".
            }
      });
   });
}

// Call your function
getSelectFieldData("${fieldHtmlId}");

Once it works move the code to a separate .js file in which you can create a proper javascript class so it can be documented and reused etc.

zlu
Champ in-the-making
Champ in-the-making
Thanks Erik,

It works well. Great help from you.

Cheers,
Daniel

Hi,

If your new to this its probably easiest to start by creating it inline, inside the template just to get it working…

First create a combobox and assign it the unique guid that the forms runtime gives you, i.e.:

<select id="${fieldHtmlId}"></select>

Then inside a <script> tag do something like this:

var getSelectFieldData = function(fieldId)
{
   // First make sure the select element is found in the dom…
   YAHOO.util.Event.onContentReady(fieldId, function()
   {
      // …found it, now ask your custom repo webscript for the data…
      var selectEl = YAHOO.util.Dom.get(fieldId);
      Alfresco.util.Ajax.jsonGet(
      {
         url: Alfresco.constants.PROXY_URI + '/your/custom/webscript',
         successCallback:
         {
            fn: function loadWebscript_successCallback(response, config)
            {
               // …data is now received, now populate the select element
               // todo: Add <option> elements to "selectEl".
            }
      });
   });
}

// Call your function
getSelectFieldData("${fieldHtmlId}");

Once it works move the code to a separate .js file in which you can create a proper javascript class so it can be documented and reused etc.

sgangapa
Champ in-the-making
Champ in-the-making
Could you pls. share the integrated sample code?..