Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#789658
Hello,

I see that one can use:
var caseId = $("[name=APP_UID]").val();
to get the current case's App_UId.

Similarly, is there a way to get the current user's USR_USERNAME or USR_UID info with Javascript. I am trying to not use triggers and to depend only on Javascript.

Many thanks in advance.
SGK
#815929
Create a text or hidden field in your Dynaform which is associated with either the USR_USERNAME or USER_LOGGED variable:
userInfoForm.png
userInfoForm.png (69.1 KiB) Viewed 11629 times
If you want to get this information with JavaScript, then add this JavaScript to your form:
getUserInfoJavascript.png
getUserInfoJavascript.png (52.08 KiB) Viewed 11629 times
This will only work when displaying a Dynaform while running a case. It won't work in the Dynaform designer.

Here is a sample process to test it:
(24.12 KiB) Downloaded 672 times
#815951
You can set the default value property for text fields in grids in the same way. See the attached process:
gridWithInsertedUsernameUserId.png
gridWithInsertedUsernameUserId.png (15.02 KiB) Viewed 11613 times
You can also use JavaScript to insert the username in a grid using grid.setValue() and grid.onAddRow(), but that is more complicated.
Attachments
(24.3 KiB) Downloaded 573 times
#815955
Thanks! for your reply amosbatto but I have tried that already but it doesn't work, anyway I have tried another approach and it worked for me using the below line of code.

$("#grd_DeptApproval").setValue($("#USR_USERNAME").getValue(), '1', '2');

and I managed to get the username whenever the add new row button is clicked by using this code

$("#grd_DeptApproval").onAddRow(function(aNewRow, oGrid, rowIndex) {
//if an even row in the grid
if (rowIndex % 2 == 0) {
//set the value for the chosen field
aNewRow[1].setValue($("#USR_USERNAME").getValue(), '2', '2');
}
});

but as you can see this will only work for the row number 2 and won't work after that so how can I make this more dynamic and also because if the user didn't add a new row in his step in the next step it won't work so how can I avoid this also I need to lock the previous rows from editing in the next steps for the other users is that can be done or not.

Thanks! again for your help.
Attachments
2018-09-06_8-16-33.jpg
2018-09-06_8-16-33.jpg (32.6 KiB) Viewed 11610 times
#826337
amosbatto wrote: Tue Sep 04, 2018 9:48 pm Create a text or hidden field in your Dynaform which is associated with either the USR_USERNAME or USER_LOGGED variable:
userInfoForm.png

If you want to get this information with JavaScript, then add this JavaScript to your form:
getUserInfoJavascript.png

This will only work when displaying a Dynaform while running a case. It won't work in the Dynaform designer.

Here is a sample process to test it:
Get_user_Info-1.pmx
Hi,

Once I get the userId, can I get the lastname and firstname in the Dynaform?
I try to use the function infoUser but it doesen't work :
Code: Select all
var userId = $("#USER_LOGGED").getValue();
alert('User ID      '+userId);  
var data = userInfo(userId);
var fname = data['firstname'];
var lname = data['lastname'];
alert('First name      '+ fname);  
Thanks in advance
#826355
HSaber wrote: Thu Sep 06, 2018 1:40 am Thanks! for your reply amosbatto but I have tried that already but it doesn't work, anyway I have tried another approach and it worked for me using the below line of code.

$("#grd_DeptApproval").setValue($("#USR_USERNAME").getValue(), '1', '2');

and I managed to get the username whenever the add new row button is clicked by using this code

$("#grd_DeptApproval").onAddRow(function(aNewRow, oGrid, rowIndex) {
//if an even row in the grid
if (rowIndex % 2 == 0) {
//set the value for the chosen field
aNewRow[1].setValue($("#USR_USERNAME").getValue(), '2', '2');
}
});

but as you can see this will only work for the row number 2 and won't work after that so how can I make this more
You need to get rid of the code limiting it to only even rows. Use this:
Code: Select all
$("#grd_DeptApproval").onAddRow(function(aNewRow, oGrid, rowIndex) {
    //set the value for the second field in the new row field
    var username = $("#USR_USERNAME").getValue();
    aNewRow[1].setValue(username, rowIndex, 2);                  
}); 
#826356
livier wrote: Wed Sep 04, 2019 12:31 am Once I get the userId, can I get the lastname and firstname in the Dynaform?
I try to use the function infoUser but it doesen't work :
Code: Select all
var userId = $("#USER_LOGGED").getValue();
alert('User ID      '+userId);  
var data = userInfo(userId);
var fname = data['firstname'];
var lname = data['lastname'];
alert('First name      '+ fname);  
userInfo() only works with PHP code inside triggers.
You should create a hidden field in the Dyanform which is associated with the variable "userInformation".
Then, create a trigger which is set to fire before the Dynaform and has the following code:
Code: Select all
$aUser = userInfo(@@USER_LOGGED);
@@userInformation = json_encode($aUser);

Then, add the following JavaScript to your Dynaform:
Code: Select all
var sUser = $("#userInformation").getValue();
if (sUser) {
    var oUser = JSON.parse(sUser);
    var firstName = oUser.firstname;
    var lastName = oUser.lastname;
    var username = oUser.lastname;
    alert(firstName+' '+lastName+' says hi!');
} 
#826367
Thank you for your answer.
I've created a trigger and two hidden fields.
In my trigger I get the lastname and the firstname in two variables.
I'm new with processmaker and I didn't know the use of the JSON.parse function.
Thank you very much

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]