cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

How do I automatically input a value into a field, based off the value of another field?

Hi!  I am trying to auto insert a runtime value into a field based on the content of another.  Both fields are open text fields.

If the User inputs "various" into PlanName.  I would like "various" to auto-appear in the PlanNumber field.  The JS I have doesn't work accordingly.  Please help!

  if(spUtilities.nintexControl("PlanName").val() == "various") spUtilities.nintexControl("PlanNumber").val("various");

Tags (2)
0 Kudos
Reply
5 Replies
Workflow Hero

Re: How do I automatically input a value into a field, based off the value of another field?

Are you using Classic or Responsive Forms? 

You say that you're just using two open ("open" in this case I assume meaning "enabled" and able to be altered at any given time by a user), and if one of the Controls contains the word "various" you'd like the word "various" to appear as the Value of the second Control, yes? 

  • What happens if someone then erases the value from the Second Control?
    • Should they be able to? Should it be locked down?
  • Would this information better be displayed by something such as a Calculated Value?
  • Is there a Default message that exists in the Second Control when the word Various doesn't exist in the First Control?
  • Are there any other 'keywords' that require a similar methodology?

Please provide answers and context for the above questions, as it could be useful in allowing people to generate an answer for you. 

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How do I automatically input a value into a field, based off the value of another field?

Thank you for the reply!

If they type Various (or various) in Plan Name, I would like Various to appear in Plan Number.  But would also like them to have the ability to type over the Various wording.

No default messaging int he 2nd control.  Typically, they would just enter a contract number.  But on occasion, there are several contract numbers, to which we would just accept the word Various.  Though, if there are only 2 numbers, I'd like them to have the ability to type over the word if they wish.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How do I automatically input a value into a field, based off the value of another field?

Alrighty. 

And one last one (which I just thought of) 

What happens if there is already something in that second control where the word 'Various' should appear suddenly? Should it just overwrite everything, get added as a prefix or suffix, or just not show up at all? 

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How do I automatically input a value into a field, based off the value of another field?

Thanks again for your help!

If something already exists in that 2nd field, I would like for it to stay.  So the "Various" would only pop in there IF the field is blank.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How do I automatically input a value into a field, based off the value of another field?

In my test form I have (2) Label Controls and (2) Single Line Text Controls 

First Single Line Text Control:

Second Single Line Text Control: 

on the Second Single Line Text Control, Create a Formatting Rule:

(Note: You do not need to select either Disable or Hide as we are just using this to interact with the control it's attached on and aren't actually formatting it )

...and insert the following text: 

(function(formControlCall, inputVal) {
  "use strict";

  var formControlID = formControlCall.split("'")[1] || "";
  var targetControl = sourceContext.find("[formcontrolid='" + formControlID + "'].nf-filler-control");
  var targetInput = NWF$(targetControl.find("[formcontrolid][id]")[0]);

  if (inputVal.match(/various/gi) !== null && !targetInput.val()) {   
    targetInput.trigger("focus").val("Various").trigger("blur");
  }

  return false;
}("{ControlSmiley Frustratedelf}", First_Input))

(Note: At the very bottom there, 'First_Input' should be the actual reference to the named control on the form. Here is a picture showing what the formula should look like in your editor

This will input the word "Various" inside of the Second Input Control, so long as the First Input Control contains the word (in any upper or lowercase format) - anywhere in the text AND only if the second field is empty. 

Not exactly a pretty way of achieving this, but if it works for you and your users are happy, it works. 

Hope it helps! 

0 Kudos
Accept as Solution Reply