Skip to main content
Nintex Community Menu Bar
Question

UpdateData not working ....

  • July 9, 2024
  • 15 replies
  • 41 views

Forum|alt.badge.img+7

I am using below code in my java script for activate condition. But This code is not working properly.
It is always fetch old data(The data which i have last saved.)

var LastNamecondition = Agcontact.getConditionByName(‘LastName’);    Agcontact.setCondition(LastNamecondition,‘Vakhariya’,true);
 Agcontact.updateData();

15 replies

Forum|alt.badge.img+18

A few things to check:

  • Does your model Agcontact have a condition on it set to “Filterable…” with the name “LastName”?
  • What type of condition is it? You probably want ‘single specified value’ if you’re going to be setting it programatically.


Forum|alt.badge.img+7

I have set everything.Check my code.

====================

<

Forum|alt.badge.img+18

I’m not an expert, but the model looks fine to me. The only thing I’d question is the novaluebehavior… don’t think you want that for a fieldtext condition.

There might be better ways, but you could add a callback to your updateData() to see if it’s running:

Agcontact.updateData(function(result){<br>&nbsp;if (result.totalsuccess) {<br> console.log('Query was successful');<br> } else {<br> console.log('Query failed.');<br> }<br>});

Forum|alt.badge.img+7

I have already tried that.It is not working.


Forum|alt.badge.img+18

Not sure what you mean. Is the query failing, or is it running successfully, just not giving you the results you expect?


Forum|alt.badge.img+7

It is not giving me expected result.


Forum|alt.badge.img+18

Hmm. That’s frustrating. I’m assuming there’s data in your object that matches the conditions? Are you setting more that one condition at a time, or just one?


Forum|alt.badge.img+7

More than one condition.


Forum|alt.badge.img+18

Rohit,

Can you share your entire check_duplicate snippet? That might help troubleshoot.


Forum|alt.badge.img+7
 var params = arguments[0],
    step = params.step,
    stepEditor = step.editor,
  $ = skuid.$; 
stepEditor.clearMessages();
var contactModel=skuid.model.getModel("AddContact");
var raw=contactModel.getFirstRow();
var Firstname2=raw.FirstName;
var Middlename2=raw.MiddleName;
var LastName2=raw.LastName;
var Birthdate2=raw.Birthdate;
var Name='';    
if(Firstname2!==undefined)
{
    Name+=Firstname2;
}
if(Middlename2!==undefined)
{
    Name+=' '+Middlename2;
}
if(LastName2!==undefined)
{
    Name+=' '+LastName2;
}

if(Firstname2===undefined  || LastName2===undefined){
    
    alert('Please Enter First Name, Last Name');
    return false;
}

var Agcontact=skuid.model.getModel(“Agcontact”);
// Agcontact.cancel();

if(Firstname2!==undefined){
var FirstNamecondition = Agcontact.getConditionByName(‘FirstName’);
Agcontact.setCondition(FirstNamecondition,Firstname2,false);
}
if(Middlename2!==undefined){
var Middlenamecondition = Agcontact.getConditionByName(‘MiddleName’);
Agcontact.setCondition(Middlenamecondition,Middlename2,false);
}
if(LastName2!==undefined){
var LastNamecondition = Agcontact.getConditionByName(‘LastName’);
Agcontact.setCondition(LastNamecondition,LastName2,false);
}

if(Birthdate2!==undefined){
var bd=new Date(Birthdate2);
var ageDifMs = Date.now() - bd.getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
var age=Math.abs(ageDate.getUTCFullYear() - 1970);
if(age<18){
alert(“Candidate’s age is less than 18”);
}
var Birthdatecondition = Agcontact.getConditionByName(‘Birthdate’);
Agcontact.setCondition(Birthdatecondition,Birthdate2,false);
}
Agcontact.updateData();
skuid.model.updateData([Agcontact]);
Agcontact.updateData();
console.log(‘Rohit’);
console.log(Agcontact);
console.log(Agcontact.soql);
try{
if(Agcontact.getRows().length>0)
{
var messages = ;
var msg = ;
msg.message=Name+’ is already registor.Do you want to continue?..Click me’;
msg.severity=‘WARNING’;
messages.push(msg);
if (messages.length) {
var r = confirm(Name+’ is already registor’);
if (r === true) {
return true;
} else {
stepEditor.handleMessages(messages);
return false;
}

}

}

}catch(e){

}


Forum|alt.badge.img+18

Everything looks good to me until we get here: Agcontact.updateData(); skuid.model.updateData([Agcontact]); Agcontact.updateData(); Why call updateData() three times? Of course, liking good to me doesn’t mean much. Hopefully the skuid folks will jump in any time now…


Forum|alt.badge.img+7

It is only for checking.If any one working fine i will remove other.


Forum|alt.badge.img+9

I took the liberty of rewriting your snippet, let me know if your still having any issues.

var params = arguments[0],&nbsp; &nbsp; step = params.step,<br>&nbsp; &nbsp; stepEditor = step.editor,<br>&nbsp; &nbsp; $ = skuid.$;&nbsp;<br>stepEditor.clearMessages();<br>var contactModel=skuid.model.getModel("AddContact");<br>var Agcontact=skuid.model.getModel("Agcontact");<br>var row=contactModel.getFirstRow();<br>var Firstname2=row.FirstName;<br>var Middlename2=row.MiddleName;<br>var LastName2=row.LastName;<br>var Birthdate2=row.Birthdate;<br>//If you don't have a first or last name stop here. You only have to check this once<br>if(!Firstname2 &nbsp;|| !LastName2){ &nbsp; &nbsp;<br>&nbsp; &nbsp; alert('Please Enter First Name, Last Name');<br>&nbsp; &nbsp; return false;<br>}<br>var Name=Firstname2;<br>if(Middlename2!==undefined){<br>&nbsp; &nbsp; Name+=' '+Middlename2;<br>}<br>Name+=' '+LastName2;<br>//set first name condition<br>Agcontact.setCondition(Agcontact.getConditionByName('FirstName'),Firstname2,false);<br>//set middle name condition<br>if(Middlename2!==undefined){<br>&nbsp; &nbsp; Agcontact.setCondition(Agcontact.getConditionByName('MiddleName'),Middlename2,false);<br>}<br>//set last name condition<br>Agcontact.setCondition(Agcontact.getConditionByName('LastName'),LastName2,false);<br>if(Birthdate2!==undefined){<br>&nbsp; &nbsp; var bd=new Date(Birthdate2); &nbsp;<br>&nbsp; &nbsp; var ageDifMs = Date.now() - bd.getTime();<br>&nbsp; &nbsp; var ageDate = new Date(ageDifMs); // miliseconds from epoch<br>&nbsp; &nbsp; var age=Math.abs(ageDate.getUTCFullYear() - 1970);<br>&nbsp; &nbsp; if(age&lt;18){<br>&nbsp; &nbsp; alert("Candidate’s age is less than 18"); &nbsp; &nbsp;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; var Birthdatecondition = Agcontact.getConditionByName('Birthdate');<br>&nbsp; &nbsp; Agcontact.setCondition(Birthdatecondition,Birthdate2,false);<br>}<br>Agcontact.updateData(function(){//this function will run after updateData is finished<br>if(Agcontact.data.length){<br> &nbsp; &nbsp;var messages = [];<br> &nbsp; &nbsp;var msg = {};<br> &nbsp; &nbsp;msg.message=Name+' is already registor.Do you want to continue?...Click me';<br> &nbsp; &nbsp;msg.severity='WARNING';<br> &nbsp; &nbsp;messages.push(msg);<br>if (messages.length) {<br>var r = confirm(Name+' is already registor');<br>if (r === true) {<br> &nbsp; return true;<br>} else {<br> &nbsp; &nbsp; &nbsp; stepEditor.handleMessages(messages);<br> &nbsp; &nbsp; &nbsp; return false;<br>}<br>} &nbsp; &nbsp; &nbsp; &nbsp;<br>}<br>});




Forum|alt.badge.img+8

updateData is a asynchronous operation, that means that javascript will not wait for a response before executing the code written after updateData.  If you want to wait for a result and do something with it, you will have to provide a callback function, or use the Deferred Promise object that is returned by the updateData call.


Forum|alt.badge.img+7

Thanks Moshe and Matt. it is working after small correction.