how to get logged in User Name and current user system date time in instantiation Form

I am a beginner in Bonita working on a project 

My requirement is to get logged in username and current user system date time 

For Username: In business variable default value script I have tried writing the below code 

def userName= apiAccessor.getIdentityAPI().getUser(userId).getUserName(); 

//but how can i get userId as it is an instantiation  Form 

For current user system date time :I have tried below code in business variable default value script 

import java.time.*

LocalDateTime currentdatetime = LocalDateTime.now();

configBdgtWiseApproverVar.createdOn = currentdatetime

getting below error 
Caused by: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.codehaus.groovy.runtime.typehandling.GroovyCastException with message = Cannot cast object '2020-08-11T18:46:29.483977300' with class 'java.time.LocalDateTime' to class 'java.time.OffsetDateTime'

Please suggest  

 

Hello,

the server-side is not running by a user, so that's why in operation, you will not have any "userId". You have to capture this information on the form, and send it in the contract.

To do that:

* You can use the REST API "unused" (do a F12 and access the Bonita Portal: you will see this REST API)

* or use the REST API CONTEXT : it will give you this information too https://community.bonitasoft.com/project/restapicontext

if you want to use this information in a connector, you can search in the API who execute the task. It's not so simple, but more secure if you don't want to trust the contract.

For the time, depending on what you have in your BDM configBdgtWiseApproverVar.createdOn

It seems the BDM expect a java.time.OffsetDateTime

so, use 

OffsetDateTime.now()

Hope this help