- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2023 07:19 AM - edited ‎09-27-2023 07:22 AM
Error Messaging:
When creating or editing a user, if an account was previously selected, and a region is then selected, that is different than the region for the Account that was previously slected, an error message needs to be presented "There are Account(s) in the Account Access field are not in the selected Region. Either remove the selected Account from the Account Access field or select a different Region.".
As below I am attaching the screenshot . Please can suggest me scripting part.
Thank you in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2023 11:15 AM
Hi @Rai Shivam Ajay,
You can write onchange client script on account field and manipulate in script include like below
Script include name-AccountRegionLookup
Client callable to true.
var AccountRegionLookup = Class.create();
AccountRegionLookup.prototype = {
initialize: function() {},
getRegionForAccount: function() {
var accountGR = new GlideRecord('account_table'); // Replace 'account_table' with your actual account table name
if (accountGR.get(this.getParameter(‘sysparm_accountSysID’))) {
return accountGR.region_field_name; /Replace 'region_field_name' with your actual field name for the region in the Account table
}
return '';
},
type: 'AccountRegionLookup'
};
Onchange client script on account field:
var accountField = g_form.getValue('account_field_name'); // Replace 'account_field_name' with the actual field name for the Account reference field on the form
var regionField = g_form.getValue('region_field_name'); // Replace 'region_field_name' with the actual field name for the Region field on the user form
if (accountField) {
var ga = new GlideAjax('AccountRegionLookup');
ga.addParam('sysparm_name', 'getRegionForAccount');
ga.addParam('sysparm_accountSysID', accountField);
ga.getXML(function(response) {
var accountRegion = response.responseXML.documentElement.getAttribute('answer');
if (accountRegion && accountRegion !== regionField) {
g_form.addErrorMessage('There are Account(s) in the Account Access field that are not in the selected Region. Either remove the selected Account from the Account Access field or select a different Region.');
}
});
}
Change fields and tables as per your requirements.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2023 11:15 AM
Hi @Rai Shivam Ajay,
You can write onchange client script on account field and manipulate in script include like below
Script include name-AccountRegionLookup
Client callable to true.
var AccountRegionLookup = Class.create();
AccountRegionLookup.prototype = {
initialize: function() {},
getRegionForAccount: function() {
var accountGR = new GlideRecord('account_table'); // Replace 'account_table' with your actual account table name
if (accountGR.get(this.getParameter(‘sysparm_accountSysID’))) {
return accountGR.region_field_name; /Replace 'region_field_name' with your actual field name for the region in the Account table
}
return '';
},
type: 'AccountRegionLookup'
};
Onchange client script on account field:
var accountField = g_form.getValue('account_field_name'); // Replace 'account_field_name' with the actual field name for the Account reference field on the form
var regionField = g_form.getValue('region_field_name'); // Replace 'region_field_name' with the actual field name for the Region field on the user form
if (accountField) {
var ga = new GlideAjax('AccountRegionLookup');
ga.addParam('sysparm_name', 'getRegionForAccount');
ga.addParam('sysparm_accountSysID', accountField);
ga.getXML(function(response) {
var accountRegion = response.responseXML.documentElement.getAttribute('answer');
if (accountRegion && accountRegion !== regionField) {
g_form.addErrorMessage('There are Account(s) in the Account Access field that are not in the selected Region. Either remove the selected Account from the Account Access field or select a different Region.');
}
});
}
Change fields and tables as per your requirements.
Thanks,
Anand