RE: Need to get the Asset Creator / User id in the Workflow

Dinesh M, modified 6 Years ago. Junior Member Posts: 43 Join Date: 5/27/15 Recent Posts
Dear All,

We have developed a simple liferay form (named as customer satisfaction details) which consist of 10 fields.

We have also assigned a simple workflow (Approver will approve the  details) to this form (customer satisfaction details form).
Now we want to get the user id (Who has submitted the details).

Steps tried:

1.  WorkflowConstants.CONTEXT_USER_ID --> Gives context user id (When approver appoves the details, we need user id of the Initiator / Asset creator)
2.  We checked for the Workflowintancelink table to get the details of userid.
3. we also checked the below URL
          https://dev.liferay.com/discover/portal/-/knowledge_base/7-0/leveraging-the-script-engine-in-workflow
    We tried to importing the  "AssetCategory" but it gave an error in the groovy script.

Regards
​​​​​​​Dinesh
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
What do you mean, "asset creator"? The creator of the form or the person filling out the form?

The person filling out the form will be tied to the user id of the form data itself, you don't have to go digging through the asset framework to find them.
Dinesh M, modified 6 Years ago. Junior Member Posts: 43 Join Date: 5/27/15 Recent Posts
David H NebingerWhat do you mean, "asset creator"? The creator of the form or the person filling out the form?

The person filling out the form will be tied to the user id of the form data itself, you don't have to go digging through the asset framework to find them.

Dear David,

Thanks 
As said user ID will stored in the form, but i need this user id for sending a mail to user id marking the approver cc in the mail.we are using Liferay 7.0.

We tried with workflow constant but it gives approver user id when approver approves the details

We also found that in Liferay 7.1 we have option for marking cc mail in workflow.

Can you suggest me an option to send an email to form requestor marking the approver cc.

Regards
​​​​​​​Dinesh 
Dinesh M, modified 6 Years ago. Junior Member Posts: 43 Join Date: 5/27/15 Recent Posts
Can anyone suggest me with corresponding liferay API which can be imported using groovy script 
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
No, but I don't think any of that would help really...

I mean, a notification goes out when a new task arrives, but this may or may not be a single person (in fact, best practice says to never use a single person).

​​​​​​​I have no idea what you are trying to do, but if it were along the lines of sending a notification, I'd probably find the source for the current notification classes and see how they are doing it.
Dinesh M, modified 6 Years ago. Junior Member Posts: 43 Join Date: 5/27/15 Recent Posts
Thanks David.

Let me also check the other api for solving this problem.

Also attached the detail of Workflow

Attachments:

thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
But the approver has approved? They don't already know that they approved?

In either case, this might be doable using a standard notification configuration.
Dinesh M, modified 6 Years ago. Junior Member Posts: 43 Join Date: 5/27/15 Recent Posts
David H NebingerBut the approver has approved? They don't already know that they approved?

In either case, this might be doable using a standard notification configuration.

hi David,

Approver knows they have approved the request but we have many requests & for some request, it might be rejected for certain reasons. If user request for similar kind of activity then these kind of mail with marking cc to approver.

Regards
​​​​​​​Dinesh
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Can't you just sent the notification to <user /> and<assignees />?

I did not test this, just copied a task from some workflow notification and added assignees:

&nbsp; <state>
&nbsp;&nbsp;&nbsp; <name>approved</name>
&nbsp;&nbsp;&nbsp; <metadata>{"xy":[850,50],"terminal":true}</metadata>
&nbsp;&nbsp;&nbsp; <actions>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <action>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <name>approve</name>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <script>
          <![CDATA[
          import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil
          import com.liferay.portal.kernel.workflow.WorkflowConstants
          
          WorkflowStatusManagerUtil.updateStatus(WorkflowConstants.getLabelStatus("approved"), workflowContext)]]>
        </script>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <script-language>groovy</script-language>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <execution-type>onEntry</execution-type>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </action>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <action>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <name>prepareEmail</name>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <script>
          <![CDATA[
          import com.liferay.portal.kernel.service.ServiceContext
          import com.liferay.portal.kernel.workflow.WorkflowConstants

          ServiceContext serviceContext = (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT)
          Map<String, Serializable> attributes = serviceContext.getAttributes()

          workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_NAME, "Workflow (do not reply)")
          workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SUBJECT, "Artikel " + attributes.get("title") + " genehmigt")]]></script>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <script-language>groovy</script-language>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <execution-type>onEntry</execution-type>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </action>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <notification>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <name>Approved Notification</name>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <template>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;#assign
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attributes = serviceContext.getAttributes()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; articleId = attributes["articleId"]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; articleTitle = attributes["title"]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; articleVersion = attributes["version"]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Guten Tag,&lt;br&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; das ist ein automatisch generiertes Email für ${entryType}.&lt;br&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ihr Artikel mit der Nummer ${articleId} und Version ${articleVersion} und Titel ${articleTitle} wurde genehmigt.&lt;br&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </template>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <template-language>freemarker</template-language>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <notification-type>email</notification-type>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <recipients>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <user />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <assignees />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </recipients>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <execution-type>onEntry</execution-type>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </notification>
&nbsp;&nbsp;&nbsp; </actions>
&nbsp; </state>


Please don't forget that you can use multiple notification entries, so you could send a mail to the user and maybe a different mail to the assignee.
Dinesh M, modified 6 Years ago. Junior Member Posts: 43 Join Date: 5/27/15 Recent Posts
hi Christoph Rabel,

Thanks for the Reply.
​​​​​​​
The snippet provided was related to webcontent.
We are using forms & entries are getting into asset entry table.

We have even tried the following link to get the user data but we are not getting data.

https://dev.liferay.com/discover/portal/-/knowledge_base/7-0/leveraging-the-script-engine-in-workflow

Regards
Dinesh