How to get first name of userID in embedded form

Hi all,

I have a process where I am using one embedded form . I have a use case where a user task is not initially assigned to anyone so, someone has to login and claim the task on their name . once user claim the task and on complete , I need to get assignee first name within submit function of embedded form.

by using below code , I am able to get the assignee Id but I don’t know how I can get the First Name.

< script cam-script type=“text/form-script”>
var variableManager = camForm.variableManager;
camForm.on(‘submit’, function(evt) {
var assignee Id = evt.options.urlParams.userId;

});

can anyone please help me on this.

Hi @abhi1o3,

I don’t know the JavaScript code to do this, but you have to call this service to get your details: Get a User's Profile | docs.camunda.org

Hope this helps, Ingo

I tried using that but this User profile service is getting executed after the submit function complete its execution but I need to get the First Name at the time of submit only.

it would be great if I could able to get some script to get the first Name within submit function as I am able to get the user Id but I don’t how I can get the First Name of the user by using that user Id.

Hi @abhi1o3,

You can utilize the JavaScript client library

<script cam-script type="text/form-script">
inject([ '$rootScope', '$scope', 'camAPI', function($rootScope, $scope, camAPI) {

camForm.on('submit', function(evt) {

        var loggedInUserName = $rootScope.authentication.name;

        var User = camAPI.resource('user');

        User.profile(loggedInUserName, function(err, data) {
            if (!err) {
                alert('Data: ' + JSON.stringify(data));
            }
        });

    });

}]);
</script>

Thankyou for your quick response .
I used this above code but the problem is the user.profile service is getting executed once all other statement gets executed within submit and I need to get the user’s First Name and keep it in one json object as key-value pair and create that json object as execution variable. which is not happening by using above script beacuse the below code is executing before we get the actual data from user.profile service.
variableManager.createVariable({
name: “usersDetails”,
type: ‘json’,
value: jsonObject
});

basically I need to complete the execution of user.profile service before submit function complete its execution.

Hi @abhi1o3,

Then you can call the service and store the result in a global JavaScript var on form-loaded event then call createVariable method on submit event with the JavaScript var passed as value.