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

Question

Question

Syntax for a Pattern Match in FORMS using Java Script

asked on August 19, 2015

I use the following pattern matching string in Workflow

(\w+\s\w+\W*\w*)\W

To pull a User Name from the String example 'John Smith-NS" converts to 'John Smith'

Can anyone provide the syntax to do this in Forms using Java Script.

Essentially I would need to apply the Pattern to the value of one Field and populate the Pattern Match Result in another field.

0 0

Answers

APPROVED ANSWER
replied on August 19, 2015

Give the original name field a CSS class like name and the pattern matched name field a CSS class like pmname. Then you can use

$(document).ready(function () {
  
  var re = new RegExp("(\\w+\\s\\w+\\W*\\w*)\\W");
  
  $('.name input').on('change', function() {
    var pm = $(this).val().match(re);
    $('.pmname input').val(pm[1]);
  });
  
});
1 0
SELECTED ANSWER
replied on August 20, 2015

Figured it out had to add trigger change.

.trigger('change')

so

$('.cleanpm input').val(pm[1]).trigger('change');

1 0

Replies

replied on August 19, 2015

Fantastic.

I was trying to cobble the code together but no success.

Your code works like a charm.

Thanks.

1 0
replied on August 19, 2015

I assume the '[1]' means the first match.

0 0
replied on August 19, 2015

pm is an array of matches. Your regular expression returns two matches based on the test string that's used. The second match would be the one you want to use so that's why the code sets pm[1] as the value to return (since the array is 0 based).

0 0
replied on August 20, 2015

I am now having an issue where the value I return to a Field from the above code I need to use:

 

1. In a LookUp Rule where I have multiple lookup conditions so Forms automatically adds a radio box. I used the fix (which I have used before with success) the following code to automatically check the autofill box.

$(document).ready(function () {
   function autofill() {
    $('.autofill').trigger('click');
  }
 
  $('.lookupCondition').change(autofill);
});

 

"or"

 

Alternately which often I do now I create a stored procedure to perform the lookup conditions I want and pass the value of a Field returned from the above Patten Match code.

 

However neither is working. It seems as if due to the fact that I am passing the value to the Field via JavaScript the returned value is not being recognized as I have used both the autofill and stored procedures with success in other instances.

0 0
replied on August 20, 2015

Which aspect isn't working? Are you saying that you have multiple match fields and are using JS to automatically click the autofill button, which returns the name "John Smith-NS" but that lookup no longer works or the other JS where it pattern matches "John Smith" is the one that no longer works?

If the original name is returned by the lookup, then you'll need to change the JS that does the pattern matching.

$(document).ready(function () {
  
  var re = new RegExp("(\\w+\\s\\w+\\W*\\w*)\\W");
  
  $('.name input').on('change lookup', function() {
    var pm = $(this).val().match(re);
    $('.pmname input').val(pm[1]);
  });
  
});
0 0
replied on August 20, 2015

No Pattern Match portion works fine.

I pull a value from a database that looks like 'John Smith-NS'.

I fill a field using the Java Script called Project Manager with the value 'John Smith' as a result from the Java Script code.

However I now want to use the Project Manager Field as a variable in my Stored Procedure to lookup the Username from cf_users. So I pass Project Manager as the displayname using a variable in my stored procedure and the value of '1' for is_domainaccount to return DOMAIN\jsmith. I tested my stored procedure and it works fine ( I actually use others on this form that work like a charm) but nothing gets returned to my Field called Domain Account. It seems like when I pass the Project Manager Field which is displaying 'John Smith' no value is being passed to the Stored Procedure.

USE [Lindsay_LFForms]

GO

/****** Object: StoredProcedure [dbo].[sp_Lindsay_PO_cf_users_DomainAccount] Script Date: 08/20/2015 11:11:16 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[sp_Lindsay_PO_cf_users_DomainAccount]

@DisplayName varchar(50)

AS

BEGIN

SELECT *

FROM [Lindsay_LFForms].[dbo].[cf_users] where is_domainaccount = '1' and displayname = @DisplayName

END

 

So instead I thought I will just do a normal LookUp Rule

I now get an autofill box. So I use the code and assign to CSS class to have the autofill box automatically click.

$(document).ready(function () {
   function autofill() {
    $('.autofill').trigger('click');
  }
 
  $('.lookupCondition').change(autofill);
});

This works elsewhere on other forms however my Domain Account in this case will not fill in until I manually click the autofill box.

I thought perhaps the reason neither of these are working is because I am populating the Project Manager field using JavaScript so the value is not being recognized as there has been no click, blur or any other event.

Optimally I would like to use the Stored Procedure as it avoids the autofill button and hidden fields but just find this strange as I have done both SP and Autofill before without problems the only thing different is the field is being populated as the result of JavaScript.

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

Sign in to reply to this post.