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

Question

Question

Truncate Field

asked on April 12, 2017 Show version history

Hello,

 

We're pulling data from an SQL table to populate a table with multiple rows in Forms. For a field labeled UserName, the data lists the domain name prior to the actual username. Example: DOMAIN_1\name. I want to be able to automatically remove the portion containing "DOMAIN_1\", leaving only the "name" portion in the cell. Does anyone know if this is possible, and if so, how to do it?

 

Thanks,

Michael

0 0

Replies

replied on April 12, 2017

If you have access to the SQL server, you could create a view for that table, and strip it out in SQL like:

SELECT REPLACE([userName], 'DOMAIN_1\', '') as userNameWithoutDomain, * FROM [myTable]

Substituting userName for the actual column name in your table, of course.

1 0
replied on April 12, 2017 Show version history

Something like this. 

$(document).ready(function () {        

        var username = $(".yourtextbox input").val();
        var username_split = username.split('\\');
        var username_real = username_split[1];

         $(".yourtextbox input").val(username_real);

});

 

0 0
replied on April 13, 2017

Raul,

 

   I'm not versed in JavaScript. Do I replace the yourtextbox information with the field name that I'm wanting to change? If so, what would be the proper name for that field? In the lookup rules to fill that field, it's shown as (dbo_Email)>Username (Username). Is that what I would use?

 

Thanks,

Michael

0 0
replied on April 13, 2017

Well, in taking a closer look at the table in your image, I'm wondering two things.

1. Will the data in the table depend on the "Department" drop-down menu above?

2. Will the user be allowed to add more rows using the "Add" link?

In any case the "yourtextbox" should be substituted by the Class name of the input field (see screenshot).

yourtextbox.png
yourtextbox.png (11.05 KB)
0 0
replied on April 13, 2017

Yes, the data is determined by the Department selection above.

The user will not be adding more information. This is strictly an SQL lookup rule that populates the Forms table with data from the SQL table.

I replaced the yourtextbox info with remdomain as shown below, and then added remdomain into the CSS class field. So far I'm not having any luck in getting it working.

 

$(document).ready(function () {        

        var username = $(".remdomain input").val();
        var username_split = username.split('\');
        var username_real = username_split[1];

         $(".remdomain input").val(username_real);

});

 

Thanks,

Michael

0 0
replied on April 13, 2017 Show version history

I'v seen instances where the lookup rule takes longer than the Javascript so what happens is that the script runs first and then it loads the username with no effect, so keeping it as "DOMAIN\username".

I updated the code so that it has a 4 second delay before fixing the box. 

Although it will work, it will first show "DOMAIN\username" and then update it to just "username" which might be weird to the user. To enhance it, I would actually load the username into a hidden box and then load it to the visible username box when ready; but focus first on making it work within the same textbox.

Additionally I updated the code so that it actually escapes the backslash. Try this new code.

$(document).ready(function () { 
  
  
  setTimeout(function(){

        var username = $(".remdomain input").val();
        var username_split = username.split('\\');
        var username_real = username_split[1];

         $(".remdomain input").val(username_real);
  
  }, 4000); //end of setTimeout function

});

 

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

Sign in to reply to this post.