How to get User Data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2022 07:33 AM
Hi Team,
kindly help me on below issue.
On Form we have " Bill Check box", here who made checkbox= True, that Person User name(Ref: user table) , Deprt (string), Date .., need to be populated in respective fields
Issue : On INC008354 , As a admin when I made Bill checkBox = true then It is populated my Name, Deprt in respective fields and Updated Record .
BUT when I impersonated with my colleague(Not admin) change Checkbox to TRUE, immediately data populating (with name, depart, current date), but after clicking on update button, Data Not Saving on Form. even Date too not saving on respective field .
Note : total form all fields would be READ-only except this check-box field for the users who are not Admin
Script Include: GetUserDetails
getuser:function()
{
var obj ={};
var user = new GlideRecord('sys_user');
if(user.get(gs.getUserID())
{
obj.dept=user.getDisplayValue('department');
obj.user=user.getValue('sys_id');
}
return JSON.stringify(obj);
},
Client Script : OnChange , Field : Bill CheckBox, Type: All
vat todayDate = new Date();
var today_date = formatDate(todayDate,g_user_date_format);
var value = g_form.getValue("u_bill_check_box");
if(value=="true")
{
var loginuser = new GlideAjax("GetUserDetails");
loginuser.addParam('sysparm_name', 'getuser');
loginuser.getXMLAnswer(getResponse);
}else{
g_form.setValue('u_user','');
g_form.setValue('u_department','');
g_form.setValue('u_date','');
}
function getResponse(answer){
var res = JSON.parse(answer);
g_form.setValue('u_user',loginuser.user);
g_form.setValue('u_department',loginuser.dept);
g_form.setValue('u_date',today_date);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2022 08:16 AM
You may be able to accomplish this in just the Client Script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading /*|| newValue === ''*/) {
return;
}
//Type appropriate comment here, and begin script below
var todayDate = new Date();
var today_date = formatDate(todayDate, g_user_date_format);
var value = g_form.getValue('u_bill_check_box');
if(value=='true'){
g_form.setValue('u_user', g_user.userID);
var userRef = g_form.getReference('u_user', doChange);
g_form.setValue('u_date', today_date);
} else {
g_form.setValue('u_user', '');
g_form.setValue('u_department', '');
g_form.setValue('u_date', '');
}
function doChange(userRef){
g_form.setValue('u_department',userRef.u_department);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 11:59 AM
Hi ,
I tried with your script, no success.
As a admin if I change Checkbox to True, immediately data populating , after click on update button , data saving on form , showing values.
But When my colleague(Not admin) change Checkbox to TRUE, immediately data populating (with name, depart, current date), but after clicking on update button, Data Not Saving on Form. even Date too not saving on respective field .
Not only for this user, it is happening for lot of users those who are not admin
what might be Reason. ???
Note : total form all fields would be READ-only except this check-box field for the users who are not Admin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 09:13 AM
If the data is populating on the form, the script is working as intended. Saving the data is another story. If there are ACLs on the fields or table itself that do not allow write access, that would cause the issue with saving the data after it has been populated. That would be the first I would check since you say the form is changing but not saving.