how to get node property base on node id ?

Showing results for 
Search instead for 
Did you mean: 
Active Member

how to get node property base on node id ?

i am passing node from  UI to Back end to fetch node property based on node id and set property value .

String nodeId = req.getParameter(ID);;
NodeRef node = serviceRegistry.getNodeService().getNodeRef(Long.valueOf(nodeId));
if(node!= null) {
serviceRegistry.getNodeService().setProperty(node, NOTIFICATION_IS_EMAIL_SENT, true);


Is it correct ?

1 Reply

Re: how to get node property base on node id ?

Its correct, but better to wrap as system user to avoid any permission issues. Refer the below code sample:

String nodeId = request.getParamater("nodeId"); //You can get the param from request for example

if (StringUtils.isNumeric(nodeId)) {
final NodeRef nodeReference = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() {
public NodeRef doWork() {
return nodeService.getNodeRef(Long.valueOf(nodeId));
}, AuthenticationUtil.getSystemUserName());

if (nodeReference !=null){
//Get all properties from the node
final Map<QName, Serializable> properties = nodeService.getProperties(nodeReference);


//Get A property from the node. Example: ContentModel.PROP_TITLE
final QName aProp = nodeService.getProperty(nodeReference, propQName);


nodeService.setProperty(actionedUponNodeRef, propQName, "A value");

(ACSCE, AWS SAA, Azure Admin)