- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 09:56 PM - edited 11-22-2023 10:00 PM
Dear Team,
I am working on a catalog item containing a reference type variable 'requested_for_user'. Requirement is display error message if the user selected in 'requested_for_user' field has email that starts with either 'ab' OR 'AB'.
I tried to achieve this through on change client script (on requested_for_user) and below script, but no luck
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqfremail = g_form.getReference("requested_for_user");
//if((reqfremail.substring(0,2) == "ab") ||(reqfremail.substring(0,2) == "AB")){
if ((reqfremail.email.indexOf ("ab")>-1) || (reqfremail.email.indexOf ("AB")>-1)){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB'", "error");
}
//}
}
as throwing below error
the same error is displayed in both cases i.e., when using 'substring' OR 'indexOf'.
Even I tried to remove the Email value 'email' from the client script but still did not work.
Kindly help to get this work as expected.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:05 PM
Hello @rishabh31
As you are using getReference, you must have to use callback function for the same.
Replace your script with mine:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqfremail = g_form.getReference("requested_for_user", requestEmail);
function requestEmail(reqfremail){
if ((reqfremail.email.indexOf ("ab")>-1) || (reqfremail.email.indexOf ("AB")>-1)){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB', Please select", 'info');
}
}
}
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:43 PM
Hi
The below script is also working with the use of 'substring' in place of 'indexOf'
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqfremail = g_form.getReference("requested_for_user", requestEmail);
function requestEmail(reqfremail){
//if ((reqfremail.email.indexOf ("ab")>-1) || (reqfremail.email.indexOf ("AB")>-1)){
if ((reqfremail.email.substring (0,2) < "ab") || (reqfremail.email.substring (0,2) < "AB")){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB', Please select", "error");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:05 PM
Hello @rishabh31
As you are using getReference, you must have to use callback function for the same.
Replace your script with mine:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqfremail = g_form.getReference("requested_for_user", requestEmail);
function requestEmail(reqfremail){
if ((reqfremail.email.indexOf ("ab")>-1) || (reqfremail.email.indexOf ("AB")>-1)){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB', Please select", 'info');
}
}
}
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:43 PM
Hi
The below script is also working with the use of 'substring' in place of 'indexOf'
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqfremail = g_form.getReference("requested_for_user", requestEmail);
function requestEmail(reqfremail){
//if ((reqfremail.email.indexOf ("ab")>-1) || (reqfremail.email.indexOf ("AB")>-1)){
if ((reqfremail.email.substring (0,2) < "ab") || (reqfremail.email.substring (0,2) < "AB")){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB', Please select", "error");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:07 PM - edited 11-22-2023 10:09 PM
Hi @rishabh31 ,
Try like this
if (reqfremail.email.startsWith ("ab") || reqfremail.email.startsWith ("AB")){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB'", "error");
}
https://www.w3schools.com/jsref/jsref_startswith.asp
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:12 PM
Before writting that indexOf if conditions, modify it to below. It should resolve the issue.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqfremail = g_form.getReference("requested_for_user");
//if((reqfremail.substring(0,2) == "ab") ||(reqfremail.substring(0,2) == "AB")){
if(reqfremail.email){
if ((reqfremail.email.indexOf ("ab")>-1) || (reqfremail.email.indexOf ("AB")>-1)){
g_form.showFieldMsg("requested_for_user", "Selected user email starts with 'ab' OR 'AB'", "error");
}}
//}
}