UpdateData not working ....

  • 1
  • Problem
  • Updated 4 years ago
  • Solved
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();
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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.
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
I have set everything.Check my code.

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

<skuidpage unsavedchangeswarning="yes" showsidebar="false" showheader="true" tabtooverride="Candidate__c">
   <models>
      <model id="AddContact" limit="1" query="false" createrowifnonefound="true" sobject="Contact" type="" doclone="no">
         <fields>
            <field id="FirstName"/>
            <field id="MiddleName"/>
            <field id="LastName"/>
            <field id="Id"/>
            <field id="Name"/>
            <field id="Birthdate"/>
            <field id="Suffix"/>
            <field id="HomePhone"/>
            <field id="MobilePhone"/>
            <field id="OtherPhone"/>
            <field id="spct__Primary_Phone__c"/>
            <field id="spct__Contact_Method__c"/>
            <field id="spct__Phone_Reachability__c"/>
            <field id="spct__Reason_For_Inactive__c"/>
            <field id="Email"/>
            <field id="OtherAddress"/>
            <field id="MailingAddress"/>
            <field id="MailingCity"/>
            <field id="MailingCountry"/>
            <field id="MailingCountryCode"/>
            <field id="MailingState"/>
            <field id="MailingStreet"/>
            <field id="MailingPostalCode"/>
            <field id="OtherCity"/>
            <field id="OtherCountry"/>
            <field id="OtherState"/>
            <field id="OtherStreet"/>
            <field id="OtherPostalCode"/>
            <field id="MailingStateCode"/>
            <field id="OtherCountryCode"/>
            <field id="OtherStateCode"/>
            <field id="spct__Age__c"/>
            <field id="DoNotCall"/>
            <field id="spct__Date_Of_Call__c"/>
            <field id="spct__Permanent_Region__c"/>
            <field id="spct__Permanent_Region__r.Name"/>
            <field id="spct__Current_Region__c"/>
            <field id="spct__Current_Region__r.Name"/>
         </fields>
         <conditions/>
         <actions/>
      </model>
      <model id="Candidate2" limit="1" query="false" createrowifnonefound="false" sobject="spct__Candidate__c" type="">
         <fields>
            <field id="spct__First_name__c"/>
            <field id="spct__Last_name__c"/>
            <field id="spct__Middle_name__c"/>
            <field id="spct__Prefix__c"/>
            <field id="spct__Program__c"/>
            <field id="spct__Program__r.Name"/>
            <field id="spct__Aadhar_number__c"/>
            <field id="spct__Age__c"/>
            <field id="spct__Annual_income__c"/>
            <field id="spct__BPL_number__c"/>
            <field id="spct__Beneficiary_Demographics__c"/>
            <field id="spct__Beneficiary_Entity__c"/>
            <field id="spct__Beneficiary_Settings__c"/>
            <field id="spct__Beneficiary_Socioeconomics__c"/>
            <field id="spct__Beneficiary_Status__c"/>
            <field id="spct__Beneficiary_Type__c"/>
            <field id="Name"/>
            <field id="spct__Caste__c"/>
            <field id="spct__Communication__c"/>
            <field id="spct__Contact_Method__c"/>
            <field id="spct__Contacts__c"/>
            <field id="spct__Contacts__r.Name"/>
            <field id="CreatedById"/>
            <field id="CreatedBy.Name"/>
            <field id="spct__Current_Situation__c"/>
            <field id="spct__Date_Of_Call__c"/>
            <field id="spct__Designation__c"/>
            <field id="spct__Disability_Type__c"/>
            <field id="spct__Disabled__c"/>
            <field id="spct__Distance_Travel_Preference__c"/>
            <field id="spct__Do_Not_Call__c"/>
            <field id="spct__Education_level__c"/>
            <field id="spct__Email__c"/>
            <field id="spct__Expected_Salary__c"/>
            <field id="spct__Facebook__c"/>
            <field id="spct__Folder_Location__c"/>
            <field id="spct__Funding_Requirements__c"/>
            <field id="spct__Gender__c"/>
            <field id="spct__Home_Phone__c"/>
            <field id="spct__Is_Unemployed__c"/>
            <field id="spct__Job_Category__c"/>
            <field id="LastModifiedBy.Name"/>
            <field id="spct__Linkedin__c"/>
            <field id="spct__Marital_Status__c"/>
            <field id="spct__Mobile_Phone__c"/>
            <field id="spct__Other_Phone__c"/>
            <field id="spct__PAN_number__c"/>
            <field id="spct__Partner__c"/>
            <field id="spct__Partner__r.Name"/>
            <field id="spct__Permanent_Address__c"/>
            <field id="spct__Phone_Reachability__c"/>
            <field id="spct__Picture__c"/>
            <field id="spct__Picture__r.Name"/>
            <field id="spct__Picture__r.skuid__AttachmentId__c"/>
            <field id="spct__Placed_by_Parent_Organization__c"/>
            <field id="spct__Preferred_Shift__c"/>
            <field id="spct__Present_Address__c"/>
            <field id="spct__Prev_Id__c"/>
            <field id="spct__Primary_Phone__c"/>
            <field id="spct__Ration_number__c"/>
            <field id="spct__Reason_For_Inactive__c"/>
            <field id="spct__Referred_through__c"/>
            <field id="spct__Referred_through__r.Name"/>
            <field id="spct__Registration_Date__c"/>
            <field id="spct__Religion__c"/>
            <field id="spct__Role__c"/>
            <field id="spct__SMART_Value__c"/>
            <field id="spct__Salary__c"/>
            <field id="spct__Same_Address__c"/>
            <field id="spct__Severity__c"/>
            <field id="spct__Source__c"/>
            <field id="spct__Stage__c"/>
            <field id="spct__Suffix__c"/>
            <field id="spct__Teamwork__c"/>
            <field id="spct__Twitter__c"/>
            <field id="spct__Unemployed_Since__c"/>
            <field id="spct__Voter_number__c"/>
            <field id="spct__WPS_Options__c"/>
            <field id="spct__WPS_solutions__c"/>
            <field id="spct__Willing_to_relocate__c"/>
            <field id="spct__Work_Address__c"/>
            <field id="spct__Work_Phone__c"/>
            <field id="spct__Region__c"/>
            <field id="spct__Region__r.Name"/>
            <field id="Id"/>
            <field id="spct__Birthdate__c"/>
            <field id="spct__Shift_Information__c"/>
            <field id="spct__Track_Information__c"/>
            <field id="spct__Reason_for_inactive_description__c"/>
            <field id="spct__Evaluators_Comment__c"/>
            <field id="spct__Communication_ei__c"/>
            <field id="spct__Basic_Computer__c"/>
            <field id="spct__Typing_Speed__c"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Contacts__c" operator="=" model="AddContact" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate" state="filterableon" inactive="false" name="spct__Contacts__c"/>
         </conditions>
         <actions/>
      </model>
      <model id="Work_Experience__c3" limit="5" query="false" createrowifnonefound="false" sobject="spct__Work_Experience__c" doclone="" type="">
         <fields>
            <field id="spct__Designation__c"/>
            <field id="spct__From__c"/>
            <field id="spct__Salary__c"/>
            <field id="spct__To__c"/>
            <field id="Name"/>
            <field id="spct__Placement_Candidate__c"/>
            <field id="spct__Placement_Candidate__r.Name"/>
            <field id="spct__Company__c"/>
            <field id="spct__Company__r.Name"/>
            <field id="spct__Job_Profile__c"/>
            <field id="spct__Job_Profile__r.Name"/>
            <field id="spct__Employment_proof_received__c"/>
            <field id="spct__Retention_done__c"/>
            <field id="spct__Job_Opportunity__c"/>
            <field id="spct__Job_Opportunity__r.Name"/>
            <field id="spct__Unlisted_Company__c"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Placement_Candidate__c" operator="=" model="Candidate" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="Qualification_Histroy__c1" limit="5" query="false" createrowifnonefound="false" sobject="spct__Qualification_Histroy__c" doclone="" type="" queryallrows="true">
         <fields>
            <field id="spct__Individual_Name__r.Name"/>
            <field id="spct__Passing_Year__c"/>
            <field id="spct__Percentage__c"/>
            <field id="spct__Qualification__c"/>
            <field id="spct__Individual_Name__c"/>
            <field id="spct__Subject__c"/>
            <field id="spct__College_University__c"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Individual_Name__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
         <groupby method="simple"/>
      </model>
      <model id="SpctDocument__c1" limit="5" query="false" createrowifnonefound="false" sobject="spct__SpctDocument__c" doclone="" type="">
         <fields>
            <field id="spct__Document__c"/>
            <field id="spct__Effective_date__c"/>
            <field id="spct__Notice__c"/>
            <field id="Name"/>
            <field id="spct__Stage__c"/>
            <field id="spct__Termination_date__c"/>
            <field id="spct__Title__c"/>
            <field id="spct__Type__c"/>
            <field id="spct__Counterpart__c"/>
            <field id="spct__Counterpart__r.Name"/>
            <field id="spct__Counterpart__r.spct__First_name__c"/>
            <field id="Id"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Counterpart__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery" state=""/>
         </conditions>
         <actions/>
      </model>
      <model id="Candidate_Detailed_Disabilities" limit="5" query="false" createrowifnonefound="false" sobject="spct__Candidate_Detailed_Disabilities__c" doclone="" type="">
         <fields>
            <field id="spct__Candidate__r.spct__Contacts__r.Name"/>
            <field id="spct__Candidate__c"/>
            <field id="spct__Candidate__r.Name"/>
            <field id="spct__Detailed_Disabilities__c"/>
            <field id="spct__Detailed_Disabilities__r.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Candidate__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate" state=""/>
         </conditions>
         <actions/>
      </model>
      <model id="Candidate_Skills" limit="5" query="false" createrowifnonefound="false" sobject="spct__Candidate_Skills__c" doclone="" type="">
         <fields>
            <field id="spct__Candidate__c"/>
            <field id="spct__Candidate__r.Name"/>
            <field id="spct__Skill__c"/>
            <field id="spct__Skill__r.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Candidate__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate" state=""/>
         </conditions>
         <actions/>
      </model>
      <model id="Candidate_Occupations" limit="5" query="false" createrowifnonefound="false" sobject="spct__Candidate_Occupations__c" doclone="" type="">
         <fields>
            <field id="spct__Candidate__c"/>
            <field id="spct__Candidate__r.Name"/>
            <field id="spct__Occupations__c"/>
            <field id="spct__Occupations__r.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Candidate__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="NewCases" limit="5" query="false" createrowifnonefound="false" sobject="Case" doclone="" type="">
         <fields>
            <field id="CaseNumber"/>
            <field id="Subject"/>
            <field id="Status"/>
            <field id="IsEscalated"/>
            <field id="Description"/>
            <field id="spct__Candidate_Case_Type__c"/>
            <field id="Type"/>
            <field id="OwnerId"/>
            <field id="Owner.Name"/>
            <field id="spct__Assigned_To__c"/>
            <field id="spct__Assigned_To__r.Name"/>
            <field id="Contact.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="ContactId" operator="=" model="AddContact" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="NewEvent" limit="5" query="false" createrowifnonefound="false" sobject="Event" doclone="" type="">
         <fields>
            <field id="Subject"/>
            <field id="StartDateTime"/>
            <field id="EndDateTime"/>
            <field id="Description"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="WhoId" operator="=" model="AddContact" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="Sopact_Setting_demographics" limit="20" query="true" createrowifnonefound="false" sobject="spct__Sopact_Setting__c">
         <fields>
            <field id="spct__Is_Section_Enable__c"/>
         </fields>
         <conditions>
            <condition type="fieldvalue" value="A-00001" enclosevalueinquotes="true" field="Name"/>
         </conditions>
         <actions/>
      </model>
      <model id="Sopact_Setting_disability" limit="20" query="true" createrowifnonefound="false" sobject="spct__Sopact_Setting__c">
         <fields>
            <field id="spct__Is_Section_Enable__c"/>
         </fields>
         <conditions>
            <condition type="fieldvalue" value="A-00002" enclosevalueinquotes="true" field="Name"/>
         </conditions>
         <actions/>
      </model>
      <model id="Candidate_Job_Profile__c" limit="5" query="false" createrowifnonefound="false" sobject="spct__Candidate_Job_Profile__c" doclone="" type="">
         <fields>
            <field id="spct__Candidate__c"/>
            <field id="spct__Candidate__r.Name"/>
            <field id="spct__Job_Profile__c"/>
            <field id="spct__Job_Profile__r.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Candidate__c" operator="=" novaluebehavior="deactivate" state="" inactive="false" model="Candidate2" enclosevalueinquotes="true" mergefield="Id"/>
         </conditions>
         <actions/>
      </model>
      <model id="Candidate_Language__c" limit="5" query="false" createrowifnonefound="false" sobject="spct__Candidate_Language__c" doclone="" type="">
         <fields>
            <field id="spct__Candidate__c"/>
            <field id="spct__Candidate__r.Name"/>
            <field id="spct__Language__c"/>
            <field id="spct__Language__r.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Candidate__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="Attachment" limit="5" query="true" createrowifnonefound="false" sobject="Attachment" doclone="" type="">
         <fields>
            <field id="Name"/>
            <field id="CreatedDate"/>
            <field id="ParentId"/>
            <field id="Parent.Name"/>
            <field id="Body"/>
            <field id="ContentType"/>
            <field id="Id"/>
            <field id="Description"/>
            <field id="LastModifiedDate"/>
            <field id="IsPrivate"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="ParentId" operator="=" mergefield="Id" novaluebehavior="deactivate" model="SpctDocument__c1" enclosevalueinquotes="true"/>
         </conditions>
         <actions/>
      </model>
      <model id="Training_Recommended_Candidates" limit="20" query="false" createrowifnonefound="false" sobject="spct__Training_Recommended_Candidates__c" doclone="" type="">
         <fields>
            <field id="spct__Candidate__c"/>
            <field id="spct__Candidate__r.Name"/>
            <field id="spct__Training__c"/>
            <field id="spct__Training__r.Name"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="spct__Candidate__c" operator="=" model="Candidate2" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="Agcontact" limit="1" query="true" createrowifnonefound="false" sobject="Contact" doclone="" type="">
         <fields>
            <field id="Id"/>
            <field id="FirstName"/>
            <field id="MiddleName"/>
            <field id="LastName"/>
            <field id="Birthdate"/>
         </fields>
         <conditions>
            <condition type="fieldvalue" value="" field="FirstName" operator="=" mergefield="FirstName" novaluebehavior="noquery" state="filterableon" inactive="false" name="FirstName" enclosevalueinquotes="true"/>
            <condition type="fieldvalue" value="" field="MiddleName" operator="=" mergefield="MiddleName" novaluebehavior="deactivate" state="filterableoff" inactive="true" name="MiddleName" enclosevalueinquotes="true"/>
            <condition type="fieldvalue" value="" field="LastName" operator="=" mergefield="LastName" novaluebehavior="deactivate" state="filterableoff" inactive="true" name="LastName" enclosevalueinquotes="true"/>
            <condition type="fieldvalue" value="" field="Birthdate" operator="=" mergefield="Birthdate" novaluebehavior="deactivate" state="filterableoff" inactive="true" enclosevalueinquotes="false" name="Birthdate"/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <wizard deferstepcontentsrendering="false" uniqueid="MainWizard">
         <steps>
            <step stepid="step6">
               <components>
                  <basicfieldeditor showheader="true" showsavecancel="false" model="AddContact" buttonposition="" mode="edit" layout="">
                     <columns>
                        <column width="50%">
                           <sections>
                              <section title="Registration Info" collapsible="no">
                                 <fields>
                                    <field id="FirstName" valuehalign="" type="" required="true">
                                       <renderconditions logictype="and" onhidedatabehavior="keep"/>
                                    </field>
                                    <field id="MiddleName" valuehalign="" type=""/>
                                    <field id="LastName"/>
                                    <field id="Suffix" valuehalign="" type=""/>
                                    <field id="spct__Contact_Method__c"/>
                                    <field id="Birthdate" valuehalign="" type=""/>
                                 </fields>
                              </section>
                              <section title="Current Address" collapsible="no">
                                 <fields>
                                    <field id="MailingStreet" valuehalign="" type="">
                                       <label>Street</label>
                                    </field>
                                    <field id="MailingCity" valuehalign="" type="">
                                       <label>City</label>
                                    </field>
                                    <field id="MailingStateCode" valuehalign="" type="">
                                       <label>State</label>
                                    </field>
                                    <field id="MailingCountryCode" valuehalign="" type="">
                                       <label>Country</label>
                                    </field>
                                    <field id="MailingPostalCode" valuehalign="" type="">
                                       <label>Zipcode</label>
                                    </field>
                                    <field id="spct__Current_Region__c" valuehalign="" type="" optionsource="" displaytemplate="">
                                       <searchfields/>
                                       <filters/>
                                    </field>
                                 </fields>
                                 <renderconditions logictype="and"/>
                              </section>
                           </sections>
                        </column>
                        <column width="50%">
                           <sections>
                              <section title="Phone Contact" collapsible="no">
                                 <fields>
                                    <field id="spct__Primary_Phone__c" valuehalign="" type=""/>
                                    <field id="MobilePhone"/>
                                    <field id="HomePhone" valuehalign="" type=""/>
                                    <field id="OtherPhone"/>
                                    <field id="spct__Phone_Reachability__c"/>
                                    <field id="spct__Date_Of_Call__c" valuehalign="" type=""/>
                                    <field id="DoNotCall" valuehalign="" type=""/>
                                 </fields>
                              </section>
                              <section title="Permanent Address " collapsible="no">
                                 <fields>
                                    <field id="OtherStreet" valuehalign="" type="">
                                       <label>Street</label>
                                    </field>
                                    <field id="OtherCity" valuehalign="" type="">
                                       <label>City</label>
                                    </field>
                                    <field id="OtherStateCode" valuehalign="" type="">
                                       <label>State</label>
                                    </field>
                                    <field id="OtherCountryCode" valuehalign="" type="">
                                       <label>Country</label>
                                    </field>
                                    <field id="OtherPostalCode" valuehalign="" type="">
                                       <label>Zipcode</label>
                                    </field>
                                    <field id="spct__Permanent_Region__c"/>
                                 </fields>
                                 <renderconditions logictype="and"/>
                              </section>
                              <section title="Email" collapsible="no">
                                 <fields>
                                    <field id="Email"/>
                                 </fields>
                                 <renderconditions logictype="and"/>
                              </section>
                           </sections>
                        </column>
                     </columns>
                     <renderconditions logictype="and"/>
                  </basicfieldeditor>
               </components>
               <actions>
                  <action type="multi" label="Next Step" stepid="step1" window="self" icon="sk-icon-arrow-right" url="">
                     <hotkeys/>
                     <renderconditions logictype="and"/>
                     <models>
                        <model>AddContact</model>
                     </models>
                     <actions>
                        <action type="emptyModelData">
                           <models>
                              <model>Agcontact</model>
                           </models>
                        </action>
                        <action type="custom" snippet="check_duplicate"/>
                        <action type="blockUI" message="Saving..." timeout="3000"/>
                        <action type="navigateToStep" stepid="step1"/>
                        <action type="emptyModelData">
                           <models>
                              <model>Candidate2</model>
                           </models>
                        </action>
                        <action type="createRow" model="Candidate2" appendorprepend="prepend" defaultmodefornewitems="edit"/>
                        <action type="unblockUI"/>
                     </actions>
                  </action>
               </actions>
 &nbsp
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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){
 if (result.totalsuccess) {
console.log('Query was successful');
} else {
console.log('Query failed.');
}
});
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
I have already tried that.It is not working.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Not sure what you mean. Is the query failing, or is it running successfully, just not giving you the results you expect?
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
It is not giving me expected result.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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?
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
More than one condition.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Rohit,

Can you share your entire check_duplicate snippet? That might help troubleshoot.
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
     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){
   
}

 
 
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
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.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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...
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
It is only for checking.If any one working fine i will remove other.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
I took the liberty of rewriting your snippet, let me know if your still having any issues.

var params = arguments[0],    step = params.step,
    stepEditor = step.editor,
    $ = skuid.$; 
stepEditor.clearMessages();
var contactModel=skuid.model.getModel("AddContact");
var Agcontact=skuid.model.getModel("Agcontact");
var row=contactModel.getFirstRow();
var Firstname2=row.FirstName;
var Middlename2=row.MiddleName;
var LastName2=row.LastName;
var Birthdate2=row.Birthdate;
//If you don't have a first or last name stop here. You only have to check this once
if(!Firstname2  || !LastName2){    
    alert('Please Enter First Name, Last Name');
    return false;
}
var Name=Firstname2;
if(Middlename2!==undefined){
    Name+=' '+Middlename2;
}
Name+=' '+LastName2;
//set first name condition
Agcontact.setCondition(Agcontact.getConditionByName('FirstName'),Firstname2,false);
//set middle name condition
if(Middlename2!==undefined){
    Agcontact.setCondition(Agcontact.getConditionByName('MiddleName'),Middlename2,false);
}
//set last name condition
Agcontact.setCondition(Agcontact.getConditionByName('LastName'),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(function(){//this function will run after updateData is finished
if(Agcontact.data.length){
   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;
}
}        
}
});
Photo of Rohit Vakhariya

Rohit Vakhariya

  • 1,054 Points 1k badge 2x thumb
Thanks Moshe and Matt. it is working after small correction.
(Edited)