derikvj
Canvas Initiate

Forms Validation with Popup Message

Good day,  

I would appreciate some assistance and maybe an example with regards to an issue I am faced with regarding one of my Nintex Forms.
A quick overview of my environment:

Sharepoint 2013
Nintex Workflow - Enterprise
Nintex Form – Standard

Multiple Lists with Nintex Workflows and Forms attached to each list on a specific site

List A – “New Client Details
A list with multiple columns of which some are required and should contain only unique values
The Nintex Form “attached” to this list has a number of controls connected to the relevant list columns

List B – “Current Client Details”

A list with a single Column which has been populated with Client Names

Requirement: 

When List A’s Form is open and the required, unique Client Name is inserted, I require some sort of validation / lookup to be done against the information in List B.

Should there already be an existing Client Name in List B when entering the information into List A, the user should receive an alert advising to specify a different name.

I trust that this is sufficient information to provide a solution?

Thanking you in advance.

DerikVJ

0 Kudos
Reply
6 Replies
lakshminarayana
Design Dabbler

Re: Forms Validation with Popup Message

Hi,

 

What is the data type of column in List B?

You can simply you can insert a calculated column next to your text box and set formula like 

If(lookup('List B','List B Column Name',textboxNamedControl,'List B Column Name') == '',false,true)

EX:

If(lookup('Test Request Number','Request Name',text1,'Request Name') == '',false,true)

And add a validation rule for text box like 

text2 == 'true'

But in this approach, a calculated column only generate on tab out of a text box.

Or 

You can insert a javascript code in the cutom javascript section on form settings and call this function on a button click.

It will display the alert if entered text box value present in List B column.

function findDuplicateItems()
{
var RequestNumber = NWF$('#'+textVal).val();
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Test Request Number');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><where><Eq><FieldRef Name='Title'/><value Type='Text'>"+RequestNumber+"</value></Eq></Where></Query></View>");
window.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args)
{
if(collListItem)
{
var title = '';
var RequestNumber = NWF$('#'+textVal).val();

var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
{
var oListItem = listItemEnumerator.get_current();
title = oListItem.get_item('Title');
if(title == RequestNumber)
{
alert('duplicate exists');
}
}
}
}
function onQueryFailed(sender, args)
{
alert('Request failed.');
}

0 Kudos
Reply
derikvj
Canvas Initiate

Re: Forms Validation with Popup Message

Good day Lakshmi,

Thank you very much for the provided information. Just a quick one regarding the javascript which i think will be the solution to my problem.

How would i amend it for my specific needs? I dont know javascript at all.

Do I replace the "RequestNumber" with the Client Details List name / Column name

function findDuplicateItems()

{

var RequestNumber= NWF$('#'+textVal).val();

var clientContext = new SP.ClientContext.get_current();

var oList = clientContext.get_web().get_lists().getByTitle('Title');

var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml("<View><Query><where><Eq><FieldRef Name='Title'/><value Type='Text'>"+RequestNumber+"</value></Eq></Where></Query></View>");

window.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded(sender, args)

{

if(collListItem)

{

var title = '';

var ClientDetails = NWF$('#'+textVal).val();

var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext())

{

var oListItem = listItemEnumerator.get_current();

title = oListItem.get_item('Title');

if(title == ASC Client Lookup)

{

alert('A duplicate ASC Client Name exists');

}

}

}

}

function onQueryFailed(sender, args)

{

alert(Please specify a different Client Name.');

}

 

 My lists are configured as follow:

  • Client DetailsClient Details - List

  • Client Details -  Form

            Client Details -  Form

  • ASC Client Names - List

ASC Client Name - List

0 Kudos
Reply
lakshminarayana
Design Dabbler

Re: Forms Validation with Popup Message

function findDuplicateItems()

{

var titleVal = NWF$('#'+titleVal).val();

var clientContext = new SP.ClientContext.get_current();

var oList = clientContext.get_web().get_lists().getByTitle('ASC Client Names');

var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml("<View><Query><where><Eq><FieldRef Name='Title'/><value Type='Text'>"+titleVal+"</value></Eq></Where></Query></View>");

window.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded(sender, args)

{

if(collListItem)

{

var title = '';

var titleVal = NWF$('#'+titleVal).val();

var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext())

{

var oListItem = listItemEnumerator.get_current();

title = oListItem.get_item('Title');

if(title == titleVal)

{

alert('A duplicate ASC Client Name exists');

return false;

}

}

}

}

function onQueryFailed(sender, args)

{

alert(Please specify a different Client Name.');

}

And insert this code in form settings and for 'Title' field settings name Client ID variable as 'textVal'

 

Add below in save button client click.

if(findDuplicateItems()==true){return true;}else{return false;}

0 Kudos
Reply
emha
Automation Master
Automation Master

Re: Forms Validation with Popup Message

would you mind to explain your setup with two lists where second one (List B) holds just client names?

if you made 'Client Name' unique in field's setting ('Enforce unique values' option) in List A, you wouldn't need List B at all, and likewise you wouldn't need at all any special validation and complex scripting. Uniqueness would be enforced by sharepoint itself.

0 Kudos
Reply
derikvj
Canvas Initiate

Re: Forms Validation with Popup Message

Good day Marian,

List B (ASC Client Names) is part of the same site and currently holds information (text values) which is extracted from a SQL table.

Lists

I understand and agree with you that I can remove the 'Enforce unique values' option form the "Title" column in List A (Client Details) as the value entered here will be detirmined by the names already part of List B.

Form

All I require is a lookup from the "Title" column in the "Client Details" List to the "Client Name" column in the "ASC Client Names" List and provide me with a message advising that the value I have entered in the "Title" column is already part of the "ASC Client Names" List if true.

0 Kudos
Reply
emha
Automation Master
Automation Master

Re: Forms Validation with Popup Message

1. straight to your question/problem:

I'd recommend to use lookup() function as mentioned by Lakshmi Narayana C‌ in his first option.

you do not need to complicate things with javascript at all for what you need.

assume you have following fields

listA - NewClientName connected to NewClientNameNamedControl form control

ListB - ClientName

then your validation formula might look like

IsNullOrEmpty(lookup('ListB','ClientName',NewClientNameNamedControl,'ClientName'))

2. just for my curiosity...

do you upload new clients from sharepoint back to SQL database? which system of these two is "the master" for maintaining client's data? can both insert new clients?

to be honest, I do not know details of our setup, but "feel in bones" several potential (serious) problems

0 Kudos
Reply