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

Calculated value isn't populating when controls it depends on are entered via JavaScript?

I have a calculated value in a repeating section that runs a lookup formula that outputs a value based on a lookup control populated via JavaScript and also found in the repeating section.  My problem is that the calculated control does not run (stays blank) once the lookup is populated via JavaScript.  However, when I manually enter the value, the calculated control works properly.

 

Does anyone know why this happens and how I can fix it?

Labels: (1)
0 Kudos
Reply
7 Replies
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hi @odennis1

have you tried exectuing this after you are done updating?

NWF$("your-updated-control-via-js").change() or .blur()

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hello @Tarf,

Thank you for the reply.  Do you mean add the ".change()" (or ".blur()") function after the entire script or in the same line as when I updated the value of the item?  I have found that the calculated value is working once the second of my cascading lookup is filled in.  Here is the lines of code I have used to update the lookups in my repeating section:

$row.find('.rsLookup select').val(xmlDoc.getElementsByTagName('rsLookup')[i].childNodes[0].nodeValue);
$row.find('.rsCascLookup select').val(xmlDoc.getElementsByTagName('rsCascLookup')[i].childNodes[0].nodeValue);

I have added the ".change()" function to the two lines and get a weird result. The first time I run the auto-populating repeating section script, the ".change()" function doesn't work, and every row after it is not created:

RSProblem3.png

The next time I run the auto-populating repeating section, the first line works as I would like, but after that, the second line does not fill in the second lookup, and then every other row that is supposed to be added is not:

RSProblem4.png

These results toggle back and forth each time I run my  auto-populating script.  It seems like the ".change()" method is the way to go, but it is a little puzzling how it yields these results.

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hi @odennis1,

to me it looks like you are updating the rows in a for loop? Indicated by the "i"

xmlDoc.getElementsByTagName('rsLookup')[i]

Are you sure, $row references each row?

 

To update lookup fields, I use this function (as discussed in https://community.nintex.com/t5/Nintex-for-SharePoint/Nintex-Forms-set-Lookup-value-using-javascript...)

function setDropdownLookupValue(control, lookupId) {
  //If 0 is passed, use the SelectValueMask as option value to look for
  var option_value =
    lookupId > 0 ? lookupId : NWF.FormFiller.Functions.SelectValueMask;
  // By replacing the _hid by nothing, the selector will give us the choice field
  var choiceId = control.replace("_hid", "");

  //Select the correct choice value and trigger change
  NWF$(`#${choiceId} option[value='${option_value}']`)
    .prop("selected", true)
    .change();
}

Please note that this contains modern javascript and may not work in older browsers like internet explorer. The function takes a control ($row.find(".rsLookup select)) and the id of the value you want to set it to. You can see how the control gets .change() d directly after the prop has been set.

 

Does your script also create the rows? If yes, how do you do it?

How do you indicate the row ($row) to update the elements? Wouldn´t a selector like NWF$(".rsLookup select:last") also work?

Can you provide more of your script with comments on what you are trying to achieve?

What does the console say, if you console.log($row)?

 

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hello @Tarf,

I posted another question here: https://community.nintex.com/t5/Nintex-for-SharePoint/Using-JavaScript-to-auto-fill-a-repeating-sect....  This should answer most of your questions.  I have been trying to follow the code you have provided, but I think I'm getting caught up in the "_hid" part (I don't really know what this is to be honest).  The logic is sound and I can follow what you're trying to do, but I must have some sort of syntax error.  Everything is vastly more complicated when dealing with repeating sections...

The code was working fine until I added the lookup controls (choice and text controls worked fine), so I'm sure the only issue I'm having with it is this lookup value entry.

 

Thank you for your continued help!

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hello again @Tarf,

I was able to figure out the lookup control auto-populating part of it!  However, I am still having a problem with the filtered lookup control and it not auto-populating.  It populates and the calculated value runs as I wan it to, so that's good!  I just can't figure out why this is happening, and I actually posted the question a few weeks ago (the link is what I just sent).  If there's no way of using the filtered lookup control alongside JavaScript auto-populating, then I will just have to deal with no filtering.  If there is a way, I would obviously much rather take that route.

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hi @odennis1,

your "filtered" lookup is a cascading lookup right? I see no problem why the script shouldn´t be able to set it to any valid value. Are you sure the value you want to set it to is valid? 

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Calculated value isn't populating when controls it depends on are entered via JavaScript?

Hello @Tarf,

I must be entering the right values because the repeating section I am referencing to fill in the current repeating section has the same filters, so the values should match.  Does it have something to do with the fact that the repeating section takes in the ID and not the text itself?  I've tried to attack the problem at so many different angles with no success.

0 Kudos
Reply