Alfresco javascript get custom DataList

烂漫一生 提交于 2020-03-06 03:31:12

问题


I've created a custom datalist and put some values on it. Now I try to get data values within a script that will be triggered by a rule. So far, I've trouble to get the custom datalist named test with this code:

var site = siteService.getSite(document.siteShortName);
var dataLists = site.getContainer("datalists");
var listCompany = dataLists.childByNamePath("test");

It seems that its return a null object but I can't figure it out why, I tried with

"dataLists", 
"datalists" and 
"data-lists" 

but still null object... Edit: After looking int he solr log, I have an error that says that Model tracking failed NamespaceException. Something like my model has already been defined previously

Second question: How can I acces to the data inside the datalist? Is getElementById() will work?

test dataList is like:

'test'  
  field1: name, 
  field2: company, 
  field3:number, 
  field4: number2

回答1:


I hope the below script will help you to resolve your datalist issue.

var site = siteService.getSite(document.siteShortName);
var dataListsContainer = site.getContainer("datalists");
var dataLists = dataListsContainer.getChildren();

logger.log("Data List length : " + dataLists.length);
for(var x=0;x<dataLists.length;x++)
{
    var dataList = dataLists[x]; //Get the current data list        
    var props = dataList.getProperties(); //Read the data list properties
    var title = props["cm:title"]; //read the datalist's title property
    logger.log("Data List title : " + title);

    if (title.indexOf("<data_list_title_goes_here>") > -1){ //check whether it's the required data list or not

        var dataListItems = dataList.getChildren(); //get the all datalistitems
        logger.log("Total dataListItems : " + dataListItems.length +" for " + title);
        for(var y = 0;y<dataListItems.length;y++) //Iterate all the datalistitems one by one
        {
            var dataListItem = dataListItems[y];
            var dataListItemProps = dataListItem.getProperties();    //Read all the properties of the current datalistitem      
            logger.log(dataListItemProps["namespace:propertyname"]); //read your custom property here
            logger.log(dataListItemProps["namespace:propertyname"]); //read your custom property here
            logger.log(dataListItemProps["namespace:propertyname"]); //read your custom property here
        }
    }       
}



回答2:


If you're using Server side javascript, getElementById() won't work and this is for client side javascript.

Let me try with my custom datalist and will update you. In mean time, can you please share, alfresco.log & solr.log file errors?



来源:https://stackoverflow.com/questions/38056403/alfresco-javascript-get-custom-datalist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!