- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 03:30 AM
Hello Team
My requirement is opened by and logged in user are not same, catalog item should not submit the request and it should show some error.
This has to be done using on submit client script. Please help me.
@Dr Atul G- LNG
@Anil Lande
@Ankur Bawiskar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 05:16 AM
Hello @Vinod S Patil ,
I didn't understand the term you referred to as 'opened By' because, as @Maik Skoddow mentioned, it will be populated once the item has been submitted.
So If you're referring to the variable named "opened by" in your form and want to ensure it's the same as the logged-in user, you can achieve this through an onSubmit client script. Alternatively, you might consider making the variable read-only and auto-populating it based on the logged-in user.
Here's an example of an onSubmit client script for validation:
function onSubmit() {
var loggedinUser = g_user.userID;
var openedBy = g_form.getValue('opened_by');
if (openedBy == loggedinUser) {
//g_form.showFieldMsg('opened_by', 'The Opened By user is the same as the Logged In user.', 'info');
return true;
} else {
alert("Please make sure that Opened By and Logged In user should be the same.");
return false;
}
}
Also you can refer the below link as well:
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 03:44 AM
Hi @Vinod S Patil ,
U need to have one on submit client script & a script include in order to achieve this
Client Script:
function onSubmit() {
var openedBy = g_form.getValue('opened_by');
// Call GlideAjax to get sys_id of the logged-in user
var ga = new GlideAjax('GetLoggedInUserID');
ga.addParam('sysparm_name', 'getLoggedInUserSysID');
ga.getXMLAnswer(function(response) {
var loggedInUserSysID = response;
// Compare "Opened By" with the sys_id of the logged-in user
if (openedBy !== loggedInUserSysID) {
// Display an error message
alert('Error: Opened By and Logged In User must be the same.');
// Prevent form submission
return false;
}
// Continue with form submission
return true;
});
// Ensure synchronous execution
return false;
}
Script Include:(Client callable true)
// GetLoggedInUserID.js
var GetLoggedInUserID = Class.create();
GetLoggedInUserID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLoggedInUserSysID: function() {
var userID = gs.getUserID();
return userID;
}
});
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 03:53 AM
your questions don't seem to make sense, as "Opened by" is populated on the requested items only. There is no field "Opened by" on the catalog item. So what exactly are you referring to?
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 05:16 AM
When any user submits a request opened by is set as logged in User.
Not sure why you have this requirement.
If you have different variables like requested for the you can use onSubmit client script and compare that variable with logged in user sys_id. If not same then return false.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 05:16 AM
Hello @Vinod S Patil ,
I didn't understand the term you referred to as 'opened By' because, as @Maik Skoddow mentioned, it will be populated once the item has been submitted.
So If you're referring to the variable named "opened by" in your form and want to ensure it's the same as the logged-in user, you can achieve this through an onSubmit client script. Alternatively, you might consider making the variable read-only and auto-populating it based on the logged-in user.
Here's an example of an onSubmit client script for validation:
function onSubmit() {
var loggedinUser = g_user.userID;
var openedBy = g_form.getValue('opened_by');
if (openedBy == loggedinUser) {
//g_form.showFieldMsg('opened_by', 'The Opened By user is the same as the Logged In user.', 'info');
return true;
} else {
alert("Please make sure that Opened By and Logged In user should be the same.");
return false;
}
}
Also you can refer the below link as well:
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket