You need to sign in to do that
Don't have an account?
Nicholas Patella
Adding Null/Not Null Field Value Check to List Button Script (Multiple Records)
I created a List Button on the Contacts related list that allows users to select multiple Contacts and update a specified field, which then triggers an email alert to the selected Contacts (in this case, a survey). I wanted to add an additional validation check that does the following:
Here is the current script:
I'm assuming I need to add the Settings_Survey_Type__c to the sforce.connection.query portion, but I'm not sure how to then check if that field is null or not for all Contacts in the array. Any ideas on how I would modify my script to add this check?
- Check if the value of a specific field (Settings_Survey_Type__c) on all selected Contacts is null or not null
- If any Contacts have a null value in this field, throw an error message
- If all selected Contacts have a not null value in this field, continue executing the script
Here is the current script:
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}; {!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}; if(confirm('Send survey(s) now?')) { var records1 = {!GETRECORDIDS($ObjectType.Contact)}; var newRecords = []; var contactRec = sforce.connection.query('select id,name,Send_Settings_Survey__c from Contact where id in (\'' + records1.join('\',\'') + '\')' ); var contacts = contactRec.getArray("records"); var arrayLength = contacts.length; if(records1==null || records1=='') { alert('No records selected'); } else{ for(var i=0;i<arrayLength;i++){ var con = new sforce.SObject("Contact"); con.Id = contacts[i].Id; con.Send_Settings_Survey__c = true; newRecords.push(con); } result = sforce.connection.update(newRecords); window.location.reload(); } }else{ }
I'm assuming I need to add the Settings_Survey_Type__c to the sforce.connection.query portion, but I'm not sure how to then check if that field is null or not for all Contacts in the array. Any ideas on how I would modify my script to add this check?