- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 04:32 AM - edited 01-10-2024 04:33 AM
Hello Experts,
I have created a catalog item to update user details. Fields given below
1.Select User (reference)
2.Name (string)
3.Location type (dropdown)
4.Mobile number (string)
5.Location (reference)
created catalog client script on Select user field to auto populate Name , Location type , Mobile number,Location
Now my requirement is
On workflow of the product once request is approved then automatically I need to update Name, Location type , Mobile number,Location for selected user on sys_user table.
How to achieve this by using runscript activity in workflow.
Best Regards,
Nani
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 04:49 AM - edited 01-10-2024 04:50 AM
Hello @Nani18 ,
Add the run script activity after approval activity and in that add below code:
//Add internal name of your variables and fields
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',current.variables.USER_VARIABLE_INTERNAL_NAME);
user.query();
if(user.next()){
user.name = current.variables.name;
user.location_type = current.variables.location_type;
user.mobile_no = current.variables.mobile_no;
user.location = current.variables.location;
user.update();
}
Let me know this code is work for you or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 04:36 AM
Hi @Nani18
created catalog client script on Select user field to auto populate Name , Location type , Mobile number,Location
For this you can use the Auto populate feature in SN.
https://www.youtube.com/watch?v=sXuKaV9aSNQ
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 04:41 AM
Hi,
Try below script. This will get the data from Item and update the data in user table.
(function execute(/* current, previous */) {
var itemId = workflow.scratchpad.request_item_id; // Assuming you store the request item ID in the workflow scratchpad
// Check if the request item ID is available
if (itemId) {
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(itemId)) {
var userId = reqItem.request.requested_for; // Assuming the user ID is stored in the requested_for field
// Update user record fields
var userRecord = new GlideRecord('sys_user');
if (userRecord.get(userId)) {
userRecord.setValue('name', reqItem.variables.name); // Replace with the actual field names
userRecord.setValue('location_type', reqItem.variables.location_type);
userRecord.setValue('mobile_number', reqItem.variables.mobile_number);
userRecord.setValue('location', reqItem.variables.location);
userRecord.update();
gs.info('User record updated successfully.');
} else {
gs.error('User not found.');
}
} else {
gs.error('Request item not found.');
}
} else {
gs.error('Request item ID not available.');
}
})();
Regards,
Shoheb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 04:49 AM - edited 01-10-2024 04:50 AM
Hello @Nani18 ,
Add the run script activity after approval activity and in that add below code:
//Add internal name of your variables and fields
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',current.variables.USER_VARIABLE_INTERNAL_NAME);
user.query();
if(user.next()){
user.name = current.variables.name;
user.location_type = current.variables.location_type;
user.mobile_no = current.variables.mobile_no;
user.location = current.variables.location;
user.update();
}
Let me know this code is work for you or not.