Skip to main content

I know the title only creates more questions... let me elaborate. We are building a supply request form that is used in Kuwait. Because of this, the unit cost may be in U.S. Dollars (USD) or it may be in Kuwaiti dinar (KD). Lets suppose the exchange rate is 3.290 KD to 1.00 USD; if I enter 329.00 USD in the "Estimated Unit Cost-USD" field, I want 100.000 KD (yes, the KD is rendered in 3 decimal places) to show up in the "Estimated Unit Cost-KD" field. Alternatively though, if we receive an estimate in KD and I enter 100.000 KD into the "Estimated Unit Cost-KD" field, $329.00 should show up in the "Estimated Unit Cost-USD" field.

So, I want neither field to be a calculated value so that we can enter values manually in either.

Finally, I want the "Total Estimated Cost..." fields to calculate the respected unit cost values times the requested quantity value.

Any thoughts?

Thanks and Regards,

Patrick

Hi Patrick,

more questions .. happy.png

What happens when the user enters value on both the fields? Where do you pick up the exchange conversion rates from to do your calculation ( I am assuming exchange rates will change on a daily basis?)

Why would you not want to have a calculated value that gives you the conversion depending on which value is filled?

Regards,

Shrini


Hi Shrinivas Naik‌!

Thanks for the response!

Shrinivas Naik wrote:

Where do you pick up the exchange conversion rates from to do your calculation ( I am assuming exchange rates will change on a daily basis?)

We use a general exchange rate per contract period and we may, down the road, put in a feature to update it on the fly but the actual rate is arbitrary for this use case. We will hard code it at this point. Also, if we do use a dynamic exchange rate, we would not want it to change every time the form opened so that an older request would only reflect the estimate that was calculated when the request was created.

Shrinivas Naik wrote:

...What happens when the user enters value on both the fields?...

The current tool in InfoPath just changes the opposing field, so if I enter a value in USD, it updates the KD, then if I enter a value in KD it changes the value in USD.

Shrinivas Naik wrote:

...Why would you not want to have a calculated value that gives you the conversion depending on which value is filled?

The customer likes the way the two options just fill out the other.

Thanks and Regards,

Patrick


Hi Patrick,

OK .. i will give you a quick solution to this .. hopefully it should solve your purpose. 

Do note that the event will trigger when the user adds the value (either USD or KD) and when he clicks outside or on the "lostfocus" event of the control.

Configure the following - 

USD Text box -

name - txtUSD

JS variable - varUSD

KD text Box

name - txtKD

JS Variable - varKD (JS variable is configured in the text box control properties -> advanced settings - >  "Client ID Javascript varibale name"

Form variable

1) Name - ProcessKDChange

220498_pastedImage_8.png

where txtKD - > named control for KD

2) processUSDChange

220497_pastedImage_6.png

where txtUSD -> named control for USD

Javascript 

- add the following JS to your form (form settings -> Custom javascript)

function processUSDchange(value) {

var someval = NWF$("#" + varUSD).val() * 2;
NWF$("#" + varKD).val(someval);
}

function processKDchange(value) {

NWF$("#" + varUSD).val(NWF$("#" + varKD).val());
}

Note - I haven't done the calculation and will leave that to you to complete it as I believe you would have got the gist of it and it would set up the plumbing required for you to change and control on other controls lost focus.

Regards,

Shrini

Please mark the answer as correct if it helps you answer your query , it will help other community members looking for a similar solution.


Hi Shrinivas Naik‌,

I tried your solution and here is the error I got when the form opens.

Also, the controls do not update when they lose focus.

Here is an example of the configuration of the controls...

Here is the copy/past of the code...

function processUSDchange(value) { var someval = NWF$("#" + varUSD).val() * 2;
NWF$("#" + varKD).val(someval);
}
function processKDchange(value) { NWF$("#" + varUSD).val(NWF$("#" + varKD).val());
}

Here are the Form variable configurations...

and...

I must add that the controls are in a repeating section. Should that make a difference? The form can have more than one item added to it.

Thanks and Regards,

Patrick


Hi Patrick,

This will work if its a stand alone  control. You can try to create a simple list and add two controls and add the functionality. It will definitely work as I have tried it and gave you the snippet.

"I must add that the controls are in a repeating section. Should that make a difference? The form can have more than one item added to it."

This completely changes the scenario as you cant have the JS value attached to the textbos which is inside a repeater control, You can access values in the repeater control using CSS class. I will show you some script that you can use. You would have to "harden" the code so that the function should be called either before the form submits. Repeater control has only limited events where you can wire up, it wont work on "lostfocus" of the control.

The event which I am showing below is RowAdded event, but you would need to call the function even before submitting the form as the user can change the value of the control after the row is added. Please check the following for list of all repeater events 

JavaScript events in Nintex Forms 

Ex - 

1) Add CSS class to the repeater class 

220507_pastedImage_4.png

2) COnfigure css class for both your USD and KD text boxes inside the repeater

220511_pastedImage_5.png

220512_pastedImage_6.png

3) Add the following JS

NWF.FormFiller.Events.RegisterRepeaterRowAdded(function () {

setExchangeRates('true');

});


function setExchangeRates(value)
{
var index, len;
var USD, KD;
var repValues = NWF$(".currencyrp .nf-repeater-row ");

//IGNORE FIRST HEADER ROW
for (index = 1, len = repValues.length; index < len; ++index)
{

USD = NWF$(repValuesaindex]).closest(".nf-repeater-row").find(".rpUSD input").val();
KD = NWF$(repValuesaindex]).closest(".nf-repeater-row").find(".rpKD input").val();

if ((typeof(USD) === "undefined") || (USD === null) || (isNaN(USD)) || (USD === ""))
{} else {NWF$(repValuesaindex]).closest(".nf-repeater-row").find(".rpKD input").val(USD * 2);}

if ((typeof(KD) === "undefined") || (KD === null) || (isNaN(KD)) || (KD === ""))
{} else {NWF$(repValuesaindex]).closest(".nf-repeater-row").find(".rpUSD input").val(KD / 2);}

}
}

NOTE - Following things to note..

1) This event or calculation will be fired only when you click the New repeater row

2) setExchangeRates() -- > Call this function again at the end when you are trying to submit the form so that it does a recalcutaion of all the values.

HTH..

Regards,

Shrini


Patrick Kelligan‌ Did that work for you?


Hi Shrinivas Naik‌,

I have been underwater with other tasks. I will try and work on this this week. Thanks for the response!!

Patrick


Hi Shrinivas Naik,

I am working on this again and I wanted to ask if I was supposed to remove the previous code (see code block 1) as well as the Form variables (processUSDchange and processKDchange) or keep them?

 function processUSDchange(value)
    { var someval = NWF$("#" + varUSD).val() * 2;
        NWF$("#" + varKD).val(someval);
    }
function processKDchange(value)
    { NWF$("#" + varUSD).val(NWF$("#" + varKD).val());
    }

As it stand now, the code does not seem to be working. I have commented out the first block of code and also tried it with the first block included.

Thanks and Regards,

Patrick


Hi Patrick Kelligan‌,

Please remove the earlier block and only include the one I mentioned in my last post as in my first post I did not know you were using the repeater control.

For clarity sake would you like to actually try it out on new form so that it does not clash with your existing stuff and once you see what works it will then be easier for you to troubleshoot.?

Regards,

Shrini


Hi Patrick Kelligan

I am also adding a simple list template and the Nintex form.xml which I had quickly tried to check. Add it into your environment and have a look.

I have only added the event on the repeater "added event" so you will see the calculation being done on the text boxes inside the repeater only when the next row to be added is clicked. I have also added a seperate button "recalculateEverythingbeforeSave" which is just to show that you may need to call the function again just before save so that all the values are again calculated.

In my earlier reply I had given you the links to all the repeater events. you can see what is available and what you can make use of it to get a fine user experience. Again Repeater control does not give "Lost focus" event of any text boxes inside itself.

hth.

regards,

Shrini


Hi Shrinivas Naik,

Your template worked perfectly. I will try and troubleshoot until I get mine working. I will let you know how it works out and if I have any other issues.

Thanks and Regards,

Patrick


Hi Patrick Kelligan‌,

No worries, keep me posted. If it solves your problem please mark the answer as correct as it will help other members to search for similar issues.

Regards,

Shrini


Hi Shrinivas Naik,

I got your code working but when I incorporated yours, my code that populates the requestor info outside the repeating section stops working. Any ideas? My complete JS code is as follows...

//=============================;
//  20181108
//  SR JavaScript
//  llu_Western_Employee change activity
//  llu_ContractPeriod change activity
//=============================;

NWF$(function() {
     //  When an employee is selected using llu_Western_Employee, this runs upon change
     NWF$('#'+ jsvar_EmployeeLookup_LLU).on('change', function()
     {
          setTimeout(function()
          {
               alert ("And the value is... " + NWF$('#'+ jsvar_EmpID_CAL).val());
               if (NWF$('#'+ jsvar_EmpID_CAL).val())
               {
                    NWF$('#'+ jsvar_EmpID_TXT).val(NWF$('#'+ jsvar_EmpID_CAL).val());
                    NWF$('#'+ jsvar_LastName_TXT).val(NWF$('#'+ jsvar_LastName_CAL).val());
                    NWF$('#'+ jsvar_FirstName_TXT).val(NWF$('#'+ jsvar_FirstName_CAL).val());
                    NWF$('#'+ jsvar_Email_TXT).val(NWF$('#'+ jsvar_Email_CAL).val());
                    NWF$('#'+ jsvar_Phone_TXT).val(NWF$('#'+ jsvar_Phone_CAL).val());
               }
          }, 2000);
     });
});

//===============================;
// From Shrinivas on NitexConnect;
//===============================;

function processUSDchange(value) {

     var someval = NWF$("#" + varUSD).val() * 2;
     NWF$("#" + varKD).val(someval);
}

function processKDchange(value) {

     var someval1 = NWF$("#" + varKD).val() / 2;
     NWF$("#" + varUSD).val(someval1);
}

NWF.FormFiller.Events.RegisterRepeaterRowAdded(function () {
     setExchangeRates('true');

});

function setExchangeRates(value) {
     var index, len;
     var USD, KD;
     var repValues = NWF$(".currencyrp .nf-repeater-row ");

     //IGNORE FIRST HEADER ROW;

     for (index = 1, len = repValues.length; index < len; ++index) {

          USD = NWF$(repValues1index]).closest(".nf-repeater-row").find(".rpUSD input").val();
          KD = NWF$(repValuesfindex]).closest(".nf-repeater-row").find(".rpKD input").val();
          if ((typeof (USD) === "undefined") || (USD === null) || (isNaN(USD)) || (USD === "")) {} else {
               NWF$(repValues<index]).closest(".nf-repeater-row").find(".rpKD input").val(USD * 2);
          }

          if ((typeof (KD) === "undefined") || (KD === null) || (isNaN(KD)) || (KD === "")) {} else {
               NWF$(repValuessindex]).closest(".nf-repeater-row").find(".rpUSD input").val(KD / 2);
          }

     }
}

Thanks and Regards,

Patrick


Hi Patrick Kelligan‌,

What is the data type of your requestor info control? Is it a text box? and what does it intend to do on the change event?

and you can remove both of the functions 

function processUSDchange(value) {

     var someval = NWF$("#" + varUSD).val() * 2;
     NWF$("#" + varKD).val(someval);
}

function processKDchange(value) {

     var someval1 = NWF$("#" + varKD).val() / 2;
     NWF$("#" + varUSD).val(someval1);
}

They were only added for textboxes outside your repeater control but you arent using it anyways.


Hi Shrinivas Naik,

The process is as follows... The list lookup control (llu_Western_Employee) with a Client ID JavaScript variable name of "jsvar_EmployeeLookup_LLU". The form has some calculated values controls for example cv_EmpID with a Client ID JavaScript variable name of jsvar_EmpID_CAL where the formula is a lookup function. To answer your first question then, the controls that get populated are all Single Line Textboxs.

Regards,

Patrick


Hi Patrick Kelligan‌,

I am not 100% sure why your code wouldnt work as it difficult to troubleshoot without seeing all the controls and their lookup values.

If from what I understand looking at your code all you need is at the change event of the lookup column you want the textboxes to populate from the calculated columns? correct?

If that is the case, can I ask you to use Nintex inbuilt change functions? I have changed your part of the code (its not tested but I am assuming you can correct it if there are any issues) but it should work in theory

Do you want to (just for testing and may be use this snippet if you find it okay?) replace your code bits with this one. Make sure that this is the first line of code..

NWF$(document).ready(function(){NWF$('#'+jsvar_EmployeeLookup_LLU).change(function() {valueChanged()});});

function valueChanged() {
if (NWF$('#'+ jsvar_EmpID_CAL).val())
{
NWF$('#'+ jsvar_EmpID_TXT).val(NWF$('#'+ jsvar_EmpID_CAL).val());
NWF$('#'+ jsvar_LastName_TXT).val(NWF$('#'+ jsvar_LastName_CAL).val());
NWF$('#'+ jsvar_FirstName_TXT).val(NWF$('#'+ jsvar_FirstName_CAL).val());
NWF$('#'+ jsvar_Email_TXT).val(NWF$('#'+ jsvar_Email_CAL).val());
NWF$('#'+ jsvar_Phone_TXT).val(NWF$('#'+ jsvar_Phone_CAL).val());
}
}

Let me know how it goes..

Regards,

Shrini


Hi Shrinivas Naik,

A colleague here at my company, Eudoro Espinoza‌, tinkered with it a bit for me and got it working. It seems that the way I was commenting the code was causing an issue. He removed all of my commenting and it worked. Here is the working code.

NWF$(function () {
     NWF$('#' + jsvar_EmployeeLookup_LLU).on('change', function () {
          setTimeout(function () {
               alert("And the value is... " + NWF$('#' + jsvar_EmpID_CAL).val());
               if (NWF$('#' + jsvar_EmpID_CAL).val()) {
                    NWF$('#' + jsvar_EmpID_TXT).val(NWF$('#' + jsvar_EmpID_CAL).val());
                    NWF$('#' + jsvar_LastName_TXT).val(NWF$('#' + jsvar_LastName_CAL).val());
                    NWF$('#' + jsvar_FirstName_TXT).val(NWF$('#' + jsvar_FirstName_CAL).val());
                    NWF$('#' + jsvar_Email_TXT).val(NWF$('#' + jsvar_Email_CAL).val());
                    NWF$('#' + jsvar_Phone_TXT).val(NWF$('#' + jsvar_Phone_CAL).val());
               }
          }, 2000);
     });
});

function processUSDchange(value) {
     var someval = NWF$("#" + varUSD).val() * 3.29;
     NWF$("#" + varKD).val(someval);
}

function processKDchange(value) {
     var someval1 = NWF$("#" + varKD).val() / 3.29;
     NWF$("#" + varUSD).val(someval1);
}
NWF.FormFiller.Events.RegisterRepeaterRowAdded(function () {
     setExchangeRates('true');
});

function setExchangeRates(value) {
     var index, len;
     var USD, KD;
     var repValues = NWF$(".currencyrp .nf-repeater-row ");
     for (index = 1, len = repValues.length; index < len; ++index) {
          USD = NWF$(repValues/index]).closest(".nf-repeater-row").find(".rpUSD input").val();
          KD = NWF$(repValues>index]).closest(".nf-repeater-row").find(".rpKD input").val();
          if ((typeof (USD) === "undefined") || (USD === null) || (isNaN(USD)) || (USD === "")) {} else {
               NWF$(repValuesDindex]).closest(".nf-repeater-row").find(".rpKD input").val(USD * 3.29);
          }
          if ((typeof (KD) === "undefined") || (KD === null) || (isNaN(KD)) || (KD === "")) {} else {
               NWF$(repValuesaindex]).closest(".nf-repeater-row").find(".rpUSD input").val(KD / 3.29);
          }
     }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks Eudoro and thanks to you Shrini!!

Kind Regards,

Patrick


Hi Patrick Kelligan‌,

Glad to know it all worked out happy.png

Regards,

Shrini


Reply