Check field value against reference field

Moedeb
Tera Guru

Hi,

 

I'm needing to do a check on a catalog item as it is being filled in. 

I have a text field called:

group_name 

 

What I want to do is after the field is filled in have it check the sys_user_group to see if a group name already exists that is the same.

 

I was thinking that I'd be able to do it via an onchange client script, but can't seem to get that to work.

Ultimately I want a message to come up advising that the name is already being used if it is found and to just let the person carry on if it is not found.

1 ACCEPTED SOLUTION

@Moedeb 

it means the value is not getting passed

Also I have updated the client script line as this

if(answer.toString() == 'true'){

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

18 REPLIES 18

@Moedeb 

you copied wrong script include name

the name should be checkRecords

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

Ok thanks - updated and tried again.

No error this time, but also no result as such.

I entered a name that I know was not an active group name and also one that I no is an active group name.

No messages came up and the log showed the same for both tries:

Moedeb_0-1694150684486.png

 

@Moedeb 

the name came undefined in function?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Yes it is getting an undefined value

 

It's what is added to the log because of the gs.info()

checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	checkRecordPresent: function(){
		var name = this.getParameter('sysparm_groupName');			
		var gr = new GlideRecord('sys_user_group');
		gr.addQuery('name', name); 
		gr.setLimit(1);
		gr.query();
		gs.info(); 
		return gr.hasNext();
	},
	
    type: 'checkRecords'
});

@Ankur Bawiskar 

Either way there is no message coming up if I add a group name that I know exists already and is active