You are viewing limited content. For full access, please sign in.

Question

Question

concatenate multiple fields to one

asked on November 13, 2014 Show version history

I am trying to concatenate 3 fields into one field to send to a Stored Procedure sense we can only pass one variable.  Can anyone tell me why the built in mechanics to do this does not work or help me with a script that will pull the values from 3 single line fields into a fourth single line fields with either - or | as dividers to be parsed out on the SQL side?

I am including the field description I am trying to use that calls 2 existing form fields and the current user token.  And a picture of the Live form, with both an anonymous user and the admin user calling the form.  How to get the two form field values to populate is my main problem before sending the whole string to the procedure to pull the employee info.

Any help would be appreciated. 

searchString.PNG
StringLive.PNG
StringAdminUser.PNG
searchString.PNG (31.19 KB)
StringLive.PNG (1.51 KB)
0 0

Answer

SELECTED ANSWER
replied on November 14, 2014 Show version history

You are missing a line there where I closed out the function. (Line 5). Also, you may want to move the function inside of the overall $(document).ready(function() tags you are using, or put back my $(function(){ tags to enclose the function inside grouped javascript. Just as a better practice thing and to avoid any unnecessary/false execution of code in the future.

 

Now, That said, you still will have trouble. I forgot to add a line to cause the lookup to be performed. I have fixed that in the below code. Please copy the following code precisely. 

$(function(){
   function updateSearch () {
      var str = $('.SearchID input').val() + '|' + $('.empSSN input').val() + '|' + $('.CurrUser input').val();
      $('.searchStr input').val(str);
      $('.searchStr input').trigger('change');
    });

  $('.empSSN').on('change', 'input', updateSearch);
  $('.SearchID').on('change','input', updateSearch);

});

If you still have problems, let me know, but it should be fine. 

 

When you did not include the end of the function statement in your code, you actually made it so the ActionEventListeners were not running unless at the time of the function running. That is not what you want because, as you found out, the actions you intended dont start the function, and you have to do things like use a button to initiate the function itself. 

 

 

0 0

Replies

replied on November 13, 2014 Show version history

the tokens you are using are only available if they were a part of the previous submission. They will have no values when in the first form of a process, as it seems to be the case here.

 

Instead, you should assign the "SearchID" field a CSS Class of "SearchID" the "empSSN" field a CSS Class of "empSSN" and then make a third field, with a default value of "(/_currentuser} that is hidden if you wish, and assign it a CSS Class of "CurrUser" Also, assign the searchString field a CSS Class of "searchStr"

 

Then try something along the lines of the following.

$(function(){
   function updateSearch () {
      var str = $('.SearchID input').val() + '|' + $('.empSSN input').val() + '|' + $('.CurrUser input').val();
      $('.searchStr input').val(str);
    });

  $('.empSSN').on('change', 'input', updateSearch);
  $('.SearchID').on('change','input', updateSearch);


});

 

EDIT: Anonymous users wont have a current user value, since that are anonymous. If that is the case, you may want to have a generic value instead be used for those instance. Let me know and I can help modify the code for that, but it does not seem that you want to do that based on your initial description. 

0 0
replied on November 14, 2014 Show version history

Kenneth,

 

Thank you, It is probably my lack of understanding but I could not get that to trigger on the form without triggering it as a on click function of a HTML button.  Now the Lookup field is getting the string needed, but not triggering the lookup unless that field is tabbed over.  Any ideas on how to get the searchString field to trigger the lookup?

secButton.PNG
currentJS.PNG
secButton.PNG (18.62 KB)
currentJS.PNG (28.45 KB)
0 0
SELECTED ANSWER
replied on November 14, 2014 Show version history

You are missing a line there where I closed out the function. (Line 5). Also, you may want to move the function inside of the overall $(document).ready(function() tags you are using, or put back my $(function(){ tags to enclose the function inside grouped javascript. Just as a better practice thing and to avoid any unnecessary/false execution of code in the future.

 

Now, That said, you still will have trouble. I forgot to add a line to cause the lookup to be performed. I have fixed that in the below code. Please copy the following code precisely. 

$(function(){
   function updateSearch () {
      var str = $('.SearchID input').val() + '|' + $('.empSSN input').val() + '|' + $('.CurrUser input').val();
      $('.searchStr input').val(str);
      $('.searchStr input').trigger('change');
    });

  $('.empSSN').on('change', 'input', updateSearch);
  $('.SearchID').on('change','input', updateSearch);

});

If you still have problems, let me know, but it should be fine. 

 

When you did not include the end of the function statement in your code, you actually made it so the ActionEventListeners were not running unless at the time of the function running. That is not what you want because, as you found out, the actions you intended dont start the function, and you have to do things like use a button to initiate the function itself. 

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.