cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
cjones69
Nintex Newbie

JS to clear field based on lookup selector value (specific)

I am trying to find code to clear a field in a Nintex Form when a specific value is selected in a separate lookup selector.

 

I found some information here about clearing a field based on any change at all in that separate lookup selector, but not to clear it ONLY when either of two specific choices of 8 possible are selected.

 

This is the code I used originally which clears the field based on any change to the System selector:

NWF$(document).ready(function(){  
 NWF$('#'+SystemID).change(function() {
 SystemValueChanged()
 }
 );
 NWF$('#'+RequestTypeID).includes('AdHoc Running') (function() {
 RequestTypeAdHoc()
 }
 );
 }
 );
function SystemValueChanged() {  
 NWF$('#'+PrioritySequenceID).val('');
}
function RequestTypeAdHoc() {      
 NWF$('#'+StartDateofDevelopmentID).val('');    
 }

The function I am currently concerned with is SystemValueChanged(). RequestTypeAdHoc() will be similar, clearing multiple fields when one specific value is selected from the Request Type selector.

 

So the above code works for the SystemValueChanged function. The Priority Sequence field is cleared whenever the system is changed, no matter the value. We need it only to clear if the System is NOT ID 1 or ID 2 (change on IDs 3-8).

 

Added an alert to the code to test the values returned when system is selected. It provided the usual 1;#Value01, 2;#Value02 etc., results. When I changed the code in the SystemValueChanged function to assign the lookup selector values to a variable and then use an IF statement to compare them to the required values as shown below , nothing happens at all. Not even the alerts.

function SystemValueChanged() {  
            var picker = NWF$("#"+SystemID);
alert(picker);
            var pickval = picker.val();

alert(pickval);

            // If System is changed to anything besides 1/ravecustomreport or 2/macro, clear the priority.
            if !((pickval == '1') || (pickval == '2'))        {
                        NWF$('#'+PrioritySequenceID).val('');

I have enough knowledge of JS to be dangerous, but am NOT a developer. Can anyone point me in the right direction?

 

Thanks for any assistance!

Labels: (1)
Tags (2)
0 Kudos
Reply
2 Replies
cjones69
Nintex Newbie

Re: JS to clear field based on lookup selector value (specific)

Just an FYI, the code that is not working above was supplied by a JS developer who is not familiar with Nintex. The values for the variables have been tried with just the IDs, just the text values and the combination of ID and text value that comes out of SP lookups (1;#Value01 AND 2;#Value02). I also tried using the direct field values as well (NWF$("#"+SystemID))
0 Kudos
Reply
Automation Master
Automation Master

Re: JS to clear field based on lookup selector value (specific)

try following

 

function SystemValueChanged() {  
    var pickval =  NWF$("#"+SystemID).val();
    //alert(pickval);
    var pickID = NWF.RuntimeFunctions.parseLookup(pickval,false);
    //alert(pickID);

    // If System is changed to anything besides 1/ravecustomreport or 2/macro, clear the priority.
    if (!((pickID == '1') || (pickID == '2'))){
        NWF$('#'+PrioritySequenceID).val('');
    }
}
              
0 Kudos
Reply