The CreatorCon Call for Content is officially open! Get started here.

Validate email and update records accordingly from Portal for multiple inputs

DB1
Tera Contributor

Hi All,

 

I have the following HTML, client 

 <div class="row">
            <div class="col-6 col-sm-4">	
              <div class="form-group">
                <label for="u_business_cont">Business Contact(s)</label><span class="fa fa-asterisk mandatory"></span>
                <input type="text" placeholder="Enter Business Contacts" class="form-control" name="u_business_cont" ng-model="c.nonUsr.u_business_cont" required>
                <span class="error" style="display : none;color:#ff0000;" id="nonusrbcontacts">Business Contacts is required</span>
              </div>
            </div>

            <div class="col-6 col-sm-4">
              <div class="form-group">
                <label for="u_tech_cont">Technical Contact(s)</label>
                <input type="text" placeholder="Enter Technical Contacts" class="form-control" name="u_tech_cont" ng-model="c.nonUsr.u_tech_cont">
              </div>
            </div>


          </div>

Client

 

c.addnonuser=function(contactValue1){
		var err_flag = true;
		var group_members = c.nonUsr.u_business_cont;
		var member_split = group_members.split(',');
		for (var n = 0; n < member_split.length; n++) {
			var member_info = member_split[n].trim();
			regex = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/ig;
			err_flag = regex.test(member_info);
			console.log("var err_flag = true;" +member_info);
			if (err_flag) {
				sp.alert('Please enter a valid Email');
			}
			else
			{
				err_flag = false;
			}
		}

		c.data.action = 'addnonPhUser';
		c.data.nonpcontacts = c.nonUsr;
		console.log(c.nonUsr);

	};

	c.nonUsr={
		"u_business_cont":'',
		"u_tech_cont":'',
		"u_ops_contacts":'',
		"u_product_cont": '',
		"u_billing_cont": '',
		"u_exec_bus_cont":'',
		"u_psso":'',
		"u_prod_priv_inc_cont":'',
		"u_privacy_rep":'',
		"u_safety_rep_cont":'',
		"u_support_cont":'',
		"u_critical_issue_cont":'',
		"u_edge_mon_cont":'',
		"u_health_prof_cont":''


	};

 

There are 2 string fields and it returns the value on the console - console.log(c.nonUsr); 

Example if I enter test, test@ the console returns the same.

 

I need help with the below 2 things.

1. How to validate comma separated email values if they are correct/ valid?

2. I then need to push/update them to the respective table from server side

 

Ex:

if the above email is valid and is available on the user table I need the following update

 
 
var graddexuser2 = new GlideRecord('core_company'); 
graddexuser2.addQuery('sys_id',comp1);
graddexuser2.query();
if(graddexuser2.next())
{
graddexuser2.u_billing_contact = input.bContacts.u_billing_cont.value;
graddexuser2.u_exec_bus_contact = input.bContacts.u_exec_bus_cont.value;
graddexuser2.update();
 
}
 
Help much appreciated.
 
Thanks
2 REPLIES 2

James Chun
Kilo Patron

Hey @DB1 ,

 

1. What did you mean by a 'correct/valid' email? Are you talking about the email address format or an email address that is registered in the user table?

2. To update the data, you can pass the data from client to server side. Have a read at an example here

https://developer.servicenow.com/dev.do#!/learn/courses/washingtondc/app_store_learnv2_serviceportal...

 

Cheers

DB1
Tera Contributor

Yes, the email entered on the field should be valid. Example it has to have complete email address like 

Adam@example.com. Because what if user just enters test or just name adam and leave

If the email id is valid then I can check on server side if it is available or not.

But the form should get submitted only if the field has valid email entries.

How do I validate for multiple comma separated entries