Skip to main content

Hi

 

I have an expression that works great.  A user fills out an Appit form where they are presented with 5 text boxes for donor names.  They are only required to fill out the first box, but if there are multiple donors they can fill out the others (up to 5).  Most of these forms will have 2 donor names, but sometimes more or just one.  The expression works great as it concatenates the names with a comma between each one.  This has been working perfectly for many months.  Now, the business wishes for the last comma to be the word "and" instead of the comma.  I'm scratching my head trying to figure out the simplest soltuion with the expression that I already have and how it can be changed to accomodate this request.   Here is my expression.  I hope that someone could share their insights.  Thanks for looking!

 

Replace ( dataRawParagraph, *Donor Names*, Concatenate ( tbPrimaryDonororEntityName, If ( Is Not Blank ( tbSecondaryDonorNamesA ) , ,  tbSecondaryDonorNamesA, (Empty String) ) , If ( Is Not Blank ( tbSecondaryDonorNamesB ) , ,  tbSecondaryDonorNamesB, (Empty String) ) , If ( Is Not Blank ( tbSecondaryDonorNamesC ) , ,  tbSecondaryDonorNamesC, (Empty String) ) , If ( Is Not Blank ( tbSecondaryDonorNamesD ) , ,  tbSecondaryDonorNamesD, (Empty String) ) ) )

Hi  @chasquad,


 


In your case, you will need to use some JS/Jquery, please try the following method:


 


Add a data label to your view/form to save the index of the last comma and call it dlIndexValue


Add another data label and call it dlGetLastIndex, this data label will be used to transfer the script to it to call the funtion whenever your string changes (note: select literal property of the data label)


 


in my example the view looks like below:


 


15486i4BBCE7086AFC2198.png


 


create an expression of the following script:


 


<script type="text/javascript">
$(document).ready(function()
{
var str = $(" name='dlMyValue']").text();
var n = str.lastIndexOf(",");
$(";name='dlIndexValue']").SFCLabel('option', 'text', n);});
</script>

Set the name value in the str variable with the control name that has your concatenated string.


 


now you need to design new expressions to insert 'and':


 


11503i3062229AF0FB0FD5.png


 


Replace dlMyValue with your expresion that concatenates the string.


 


result:


 


15182i4F4875E7747A823E.png


 


 


Note: If the text changes, the index value will not get updated unless you call the script/funtion again. to do that in smartforms I added a button in my example to transfer the expression(script) to a data label (dlGetLastIndex) then I clear the data lable so I can call it again.


 


you can implement this in many different ways.


 


 


Reply