Not able to get organization form node in alfresco - alfresco

Using Alfresco Community 5.0.d and not able to get organization from node.
File: pickerresults.lib.js
Method: createPersonResult(node)
function createPersonResult(node)
{
var personObject =
{
typeShort: node.typeShort,
isContainer: false,
properties: {},
displayPath: node.displayPath,
nodeRef: "" + node.nodeRef
}
// define properties for person
personObject.properties.userName = node.properties.userName;
// defining new property for the personObject but
// but not getting any value
personObject.properties.companyname = (node.properties["cm:organization"] ? node.properties["cm:organization"] : "");
personObject.properties.companyname = (node.properties.organization ? node.properties.organization : "");
return personObject;
}
Override the pickerresults.lib.js file by copying it to location as below.
/Applications/alfresco-5.0.d/tomcat/shared/classes/alfresco/extension/templates/webscripts/org/alfresco/repository/forms/pickerresults.lib.js
how could I get organization name?
also how could I debug the node properties like logger.log is there but does not work here.
Thanks.

please try to get properties without extra "." in
node.properties.["cm:organization"]
like:
node.properties["cm:organization"]
please refer this doc link
http://docs.alfresco.com/4.0/references/API-JS-ScriptNode.html
properties
Provides access to all the properties of this node. The properties returned are accessed via an associative array. Properties of a node can be accessed in the following ways:
Example: node.properties["name"]
Example: node.properties.name
example i have tried:
var node =people.getPerson("admin");
logger.log(node.properties["cm:email"]);
logger.log(node.properties.email);

Related

Get all properties for a node magnolia cms

I would like to get a list of properties for a given node in magnolia so that I can get values for each property.
I tried using the PropertyUtil but it cannot find "tags".
List<String> tags = info.magnolia.jcr.util.PropertyUtil.getValuesStringList(node.getProperty("tags").getValues());
Actual result is javax.jcr.PathNotFoundException: tags.
Expected result is a list of properties that I can use to query for property values.
It is called 'mgnl:tags', please refer to info.magnolia.contenttags.manager.TagManager#TAGS_PROPERTY
Cheers,
I was able to do it using javax.jcr Interface Node:
PropertyIterator pi = node.getProperties();
while(pi.hasNext())
{
Property p = pi.nextProperty();
String name = p.getName();
String val = p.getString();
}

Drupal 8 | Wrong alias used

Bonjour,
I have a problem on Drupal 8 that I can't solve, that's why I'm calling on you.
I have 2 aliases for the same node :
/public/event/10
/pro/event/10
I have a block_1 that only appears on the " /public/* " pages and a block_2 on the " /pro/* " pages.
When I access to the url "/pro/event/10", block_1 is displayed and not block_2.
I conclude that Drupal selects the alias "/public/event/10" (probably the first one he finds) while I'm on the page "/pro/event/10".
How can I programmatically tell Drupal the right alias to use?
Thank you in advance for your help.
Here is the code if it can help someone
class OOutboundPathProcessor implements OutboundPathProcessorInterface
{
function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
{
// Only for nodes
if (!isset($options['entity_type']) OR $options['entity_type'] !== 'node')
{
return $path;
}
// Get current 'space'
$espace = \Drupal::service('session')->get('espace');
// Get the node to process
$node = $options['entity'];
// New path
$str_path = "/%s/%s/%s";
$new_path = sprintf($str_path, $espace, $node->bundle(), $node->id());
// Check new path
$isValid = \Drupal::service('path.validator')->isValid($new_path);
if ($isValid === true) return $new_path;
return $path;
}
}
You might want to create your own path_processor_outbound service by implementing OutboundPathProcessorInterface.
This implementation may work on /node/{id} paths if the current requests path matches /public/event/** or /pro/event/**.
Analyzing the node entity for it's type (bundle): If it is event generate and return your desired path; if it is not event don't manipulate the path and return the original.
Writing the actual implementation in PHP code may be your own pleasure ;-)

How do I check to see if that element already exists before I add it?

Trying to search web.config using ConfigurationElementCollection.
Here's the article source:
https://www.iis.net/configreference/system.webserver/modules/add
Here's a snippet of c# code I'm trying to use:
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetWebConfiguration("Default Web Site/app1");
ConfigurationSection modulesSection = config.GetSection("system.webServer/modules");
ConfigurationElementCollection modulesCollection = modulesSection.GetCollection();
ConfigurationElement addElement = modulesCollection.CreateElement("remove");
addElement["name"] = #"CartHeader";
//addElement["type"] = #"Contoso.ShoppingCart.Header";
//addElement["preCondition"] = #"managedHandler";
// Check if your CartHeader module exists
var exists = modulesCollection.Any(m => m.Attributes["name"].Value.Equals("CartHeader"));
// Handle accordingly
if (!exists)
{
// Create your module here
modulesCollection.Add(addElement);
serverManager.CommitChanges();
}
}
How do I check to see if that element already exists before I add it?
I changed the CreateElement("remove") and I added a check before trying to add the element but apparently it doesn't take <remove> elements into consideration because it keeps adding it. Am I missing something?
You could likely use a bit of LINQ to query and see if an element with that specific name attribute exists via the Enumerable.Any() method :
// Check if your CartHeader module exists
var exists = modulesCollection.Any(m => m.Attributes["name"].Value.Equals("CartHeader"));
// Handle accordingly
if(!exist)
{
// Create your module here
}

How to bind a SAPUI5 control property with data out of a binding?

From time to time I have the requirement to bind a control property to based on data out of model A to another model B.
For example the syntax could look like this (but will not work):
text : "{B>/rootB/{A>someValue}/propertyB}"
I normally solve this problem by "misusing" an unused control property in combination with the format function. It would look like this:
tooltip : {
path : "A>someValue",
formatter : function(oValue) {
// do some checks on oValue
var path = "B>/rootB/"+oValue+"/propertyB";
this.bindProperty("text", path);
return undefined; // because tooltip is not used
}
The benefit of this, each time "A>someValue" will be changed the binding of "text" will be updated automatically.
It is also possible to do this in template code (like items aggregations).
But you may smell the code ;)
Any suggestions to make it cleaner?
As far as I know, there is no such possibility in UI5 (yet). I always use a formatter function as you already mentioned. I say not YET, because developers seem to be aware of this feature request: see on GitHub
BUT, you dont need to missuse a random control property! Just use the formatter to read the needed values from any model you have access to:
text : {
path : "A>someValue1",
formatter : function(oValue) {
// read model B to get someValue2 (based on someValue1)
var path = "B>/rootB/"+oValue+"/propertyB";
var B = getModel("someModel");
var someValue2 = B.getProperty(path);
return someValue2
}

Accessing the object/row being edited in Dynamic Data

I'm modifying the "Edit.aspx" default page template used by ASP.NET Dynamic Data and adding some additional controls. I know that I can find the type of object being edited by looking at DetailsDataSource.GetTable().EntityType, but how can I see the actual object itself? Also, can I change the properties of the object and tell the data context to submit those changes?
Maybe you have found a solution already, however I'd like to share my expresience on this.
It turned out to be a great pita, but I've managed to obtain the editing row. I had to extract the DetailsDataSource WhereParameters and then create a query in runtime.
The code below works for tables with a single primary key. If you have compound keys, I guess, it will require modifications:
Parameter param = null;
foreach(object item in (DetailsDataSource.WhereParameters[0] as DynamicQueryStringParameter).GetWhereParameters(DetailsDataSource)) {
param = (Parameter)item;
break;
}
IQueryable query = DetailsDataSource.GetTable().GetQuery();
ParameterExpression lambdaArgument = Expression.Parameter(query.ElementType, "");
object paramValue = Convert.ChangeType(param.DefaultValue, param.Type);
Expression compareExpr = Expression.Equal(
Expression.Property(lambdaArgument, param.Name),
Expression.Constant(paramValue)
);
Expression lambda = Expression.Lambda(compareExpr, lambdaArgument);
Expression filteredQuery = Expression.Call(typeof(Queryable), "Where", new Type[] { query.ElementType }, query.Expression, lambda);
var WANTED = query.Provider.CreateQuery(filteredQuery).Cast<object>().FirstOrDefault<object>();
If it's a DD object you may be able to use FieldTemplateUserControl.FindFieldTemplate(controlId). Then if you need to you can cast it as an ITextControl to manipulate data.
Otherwise, try using this extension method to find the child control:
public static T FindControl<T>(this Control startingControl, string id) where T : Control
{
T found = startingControl.FindControl(id) as T;
if (found == null)
{
found = FindChildControl<T>(startingControl, id);
}
return found;
}
I found another solution, the other ones did not work.
In my case, I've copied Edit.aspx in /CustomPages/Devices/
Where Devices is the name of the table for which I want this custom behaviour.
Add this in Edit.aspx -> Page_Init()
DetailsDataSource.Selected += entityDataSource_Selected;
Add this in Edit.aspx :
protected void entityDataSource_Selected(object sender, EntityDataSourceSelectedEventArgs e)
{
Device device = e.Results.Cast<Device>().First();
// you have the object/row being edited !
}
Just change Device to your own table name.

Resources