AnsweredAssumed Answered

Nintex Forms Validation with executeQueryAsync

Question asked by marcosharepoint on Jul 1, 2016

Hello,

I want to validate a textbox content whether the content doesn't exist in a table column. With focusOut-Method it works great. But rechecking the same short before saving creates trouble. This is needed because another user could create another item, where the first check would fail.

 

My actual code looks like:

NWF$(window).load(function() { [...]

NWF$(tubInputSelector).focusout(function() { // doppelten Tub pro Charge prüfen

  var pathname = window.location.pathname;

  if( pathname.indexOf('EditForm') === -1){ // nur in NewForm

   checkTubInCharge();

  }

}); // focusout !

}

function checkTubInCharge(){

chargenInputValue = NWF$(chargenDropdownSelector+':selected').text();

tubInputValue = NWF$(tubInputSelector).val();

if(tubInputValue.length > 0 && chargenInputValue !== 'Bitte auswählen...'){ // wenn Tub-Wert eingegeben und Charge nicht leer...

  runCheckTubInCharge(); // ... prüfe, ob Tub in Charge bereits vergeben ist

}

}

function runCheckTubInCharge(chargenInputValue, tubInputValue){ // delegieren an loadChargenTubs()

context.executeQueryAsync(Function.createDelegate(this, this.loadChargenTubs), Function.createDelegate(this, this.onFailure));

}

function onFailure(sender, args) { alert('Failed! ' + args.get_message() + '\n' + args.get_stackTrace()); }

function loadChargenTubs(sender, args){ // fragt Liste mit Charge und Tub-Nr ab ...

var camlQuery = new SP.CamlQuery();

var caml= '<View><Query><Where><And><Eq><FieldRef Name="Sichtung" /><Value Type="Lookup">'+chargenInputValue+'</Value></Eq><Eq><FieldRef Name="Title" /><Value Type="Text">'+tubInputValue+'</Value></Eq></And></Where></Query></View>';

camlQuery.set_viewXml(caml);

fehlererfassung = list.getItems(camlQuery);

context.load(fehlererfassung); // ... und validiert das Ergebnis in evaluation()

context.executeQueryAsync(Function.createDelegate(this, this.evaluation), Function.createDelegate(this, this.onFailure));

}

function evaluation(){ // wird nach erfolgr. Abfrage ausgeführt und färbt Feld Tub-Nr rot/schwarz und setzt verstecktes Feld auf leer oder 1 - an diesem versteckten Feld haengt die NintexForms-Regel mit einer Validierung (die das Abspeichern verhindert)

var color = '';

if( fehlererfassung.get_count() > 0 ) {

  color =  '#FF0000';                                        //Rot

  NWF$(checkTubChargeInputSelector).val('');

} else {

  color= '#000000';                                           //Schwarz

  NWF$(checkTubChargeInputSelector).val('1');

}

NWF$(tubInputSelector).css('color', color);

}

 

and I added for validation

function checkTubInChargeValidation(source, arguments){

var pathname = window.location.pathname;

arguments.IsValid = true;

if( pathname.indexOf('EditForm') === -1){

  checkTubInCharge();

}

//zu schnell

if( fehlererfassung.get_count() > 0 ) {

  arguments.IsValid = false;

}else{

  //alert('Alles gut!');

}

}

 

The problem is that "fehlererfassung.get_count()" is computed too early to get the answer from the query.

Any idea?

Thanks

Outcomes